<commit_before>require 'spec_helper'

# Examples came from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/ECDSA_Prime.pdf

describe 'NIST P-192 examples' do
  let(:group) { ECDSA::Group::Nistp192 }
  
  describe 'private key generation with C and D' do
    let(:c) { <KEY> }
    
    it 'gives the right coordinates' do
      pending 'not sure how this works since the test below did not pass'
      point = group.new_point(c)
      expect(point.coords).to eq [
        0xFBA2AAC6_47884B50_4EB8CD5A_0A1287BA_BCC62163_F606A9A2,
        0xDAE6D4CC_05EF4F27_D79EE38B_71C9C8EF_4865D988_50D84AA5,
      ]
    end
  end
  
  describe 'private key generation with K' do
    let(:k) { <KEY> }
    
    it 'gives the right coordinates' do
      pending 'not sure how this works since the test below did not pass'
      point = group.new_point(k)
      expect(point.coords).to eq [
        0xFBA2AAC6_47884B50_4EB8CD5A_0A1287BA_BCC62163_F606A9A2,
        0xDAE6D4CC_05EF4F27_D79EE38B_71C9C8EF_4865D988_50D84AA5,
      ]
    end
  end
  
end

describe 'NIST P-256 signature verification example' do

  let(:group) do
    ECDSA::Group::Nistp256
  end
  
  let (:public_key) do
    group.new_point [
      0xB7E08AFD_FE94BAD3_F1DC8C73_4798BA1C_62B3A0AD_1E9EA2A3_8201CD08_89BC7A19,
      0x3603F747_959DBF7A_4BB226E4_19287290_63ADC7AE_43529E61_B563BBC6_06CC5E09, 
    ]
  end
  
  let(:digest) do
    0xA41A41A1_2A799548_211C410C_65D8133A_FDE34D28_BDD542E4_B680CF28_99C8A8C4
  end

  let(:signature) do
    ECDSA::Signature.new [
      0x2B42F576_D07F4165_FF65D1F3_B1500F81_E44C316F_1F0B3EF5_7325B69A_CA46104F,
      0xDC42C212_2D6392CD_3E3A993A_89502A81_98C1886F_E69D262C_4B329BDB_6B63FAF1,
    ]
  end
  
  it 'can verify the key is on the curve' do
    expect(group).to include public_key
  end
  
  it 'can be verify the signature' do
    result = ECDSA.check_signature!(public_key, digest, signature)
    expect(result).to eq true
  end
  
end

<commit_msg>I was confused when I wrote the last commit message, but I have gotten one of the P192 examples to pass now.<commit_after>require 'spec_helper'

# Examples came from http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/ECDSA_Prime.pdf
# Key generation procedures came from http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf

describe 'NIST P-192 examples' do
  let(:group) { ECDSA::Group::Nistp192 }

  describe 'private key generation with C and D' do
    let(:c) { <KEY> }

    it 'gives the right coordinates' do
      d = (c % (group.order - 1)) + 1
      point = group.new_point(d)
      expect(point.coords).to eq [
        0xFBA2AAC6_47884B50_4EB8CD5A_0A1287BA_BCC62163_F606A9A2,
        0xDAE6D4CC_05EF4F27_D79EE38B_71C9C8EF_4865D988_50D84AA5,
      ]
    end
  end

  describe 'private key generation with K' do
    let(:k) { <KEY> }

    it 'gives the right coordinates' do
      point = group.new_point(k)
      expect(point.coords).to eq [
        0xFBA2AAC6_47884B50_4EB8CD5A_0A1287BA_BCC62163_F606A9A2,
        0xDAE6D4CC_05EF4F27_D79EE38B_71C9C8EF_4865D988_50D84AA5,
      ]
    end
  end

end

describe 'NIST P-256 signature verification example' do

  let(:group) do
    ECDSA::Group::Nistp256
  end

  let (:public_key) do
    group.new_point [
      0xB7E08AFD_FE94BAD3_F1DC8C73_4798BA1C_62B3A0AD_1E9EA2A3_8201CD08_89BC7A19,
      0x3603F747_959DBF7A_4BB226E4_19287290_63ADC7AE_43529E61_B563BBC6_06CC5E09,
    ]
  end

  let(:digest) do
    0xA41A41A1_2A799548_211C410C_65D8133A_FDE34D28_BDD542E4_B680CF28_99C8A8C4
  end

  let(:signature) do
    ECDSA::Signature.new [
      0x2B42F576_D07F4165_FF65D1F3_B1500F81_E44C316F_1F0B3EF5_7325B69A_CA46104F,
      0xDC42C212_2D6392CD_3E3A993A_89502A81_98C1886F_E69D262C_4B329BDB_6B63FAF1,
    ]
  end

  it 'can verify the key is on the curve' do
    expect(group).to include public_key
  end

  it 'can be verify the signature' do
    result = ECDSA.check_signature!(public_key, digest, signature)
    expect(result).to eq true
  end

end


{'fraction_non_alphanumeric': 0.06934673366834171, 'fraction_numerical': 0.16959798994974876, 'mean_word_length': 3.6890459363957597, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188287', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1725, 'n_words': 298}