def add_fips_tests(cls): file_tv = open_fips_test_file("PKCS1-v1.5", "SigVer15_186-3.rsp") sections = load_test_vector(file_tv, ('SHAAlg', 'd', 'Result')) modulus = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appear # in a single line if len(test_vector) == 1: modulus = bytes_to_long(test_vector['n']) continue hashmod = load_hash_by_name(test_vector['SHAAlg']) pub_exp = bytes_to_long(test_vector['e']) public_key = RSA.construct((modulus, pub_exp)) add_method_dict = { 'P': cls.add_positive_test, 'F': cls.add_negative_test } add_method = add_method_dict[test_vector['Result']] add_method(hashmod, test_vector['Msg'], public_key, test_vector['S'])
def add_fips_tests(cls): files = ("SigGen15_186-2.txt", "SigGen15_186-3.txt") for file_name in files: file_tv = open_fips_test_file("PKCS1-v1.5", file_name) sections = load_test_vector(file_tv, ('SHAAlg', )) modulus = None private_key = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appears # in a single line if len(test_vector) == 1: modulus = test_vector['n'] continue # Exponents appear in two lines if len(test_vector) == 2: test_vector['n'] = modulus triplet = [ bytes_to_long(test_vector[x]) for x in ('n', 'e', 'd') ] private_key = RSA.construct(triplet, consistency_check=False) continue hashmod = load_hash_by_name(test_vector['SHAAlg']) cls.add_test(hashmod, test_vector['Msg'], private_key, test_vector['S'])
def add_fips_tests(cls): files = ("SigGen15_186-2.txt", "SigGen15_186-3.txt") for file_name in files: file_tv = open_fips_test_file("PKCS1-v1.5", file_name) sections = load_test_vector(file_tv, ('SHAAlg', )) modulus = None private_key = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appears # in a single line if len(test_vector) == 1: modulus = test_vector['n'] continue # Exponents appear in two lines if len(test_vector) == 2: test_vector['n'] = modulus triplet = [bytes_to_long(test_vector[x]) for x in ('n', 'e', 'd')] private_key = RSA.construct(triplet, consistency_check=False) continue hashmod = load_hash_by_name(test_vector['SHAAlg']) cls.add_test(hashmod, test_vector['Msg'], private_key, test_vector['S'])
def add_fips_tests(cls): file_tv = open_fips_test_file("PKCS1-PSS", "SigVerPSS_186-3.rsp") sections = load_test_vector(file_tv, ('SHAAlg', 'Result')) modulus = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appear # in a single line if len(test_vector) == 1: modulus = bytes_to_long(test_vector['n']) continue # p and q are not used if len(test_vector) == 2: continue hashmod = load_hash_by_name(test_vector['SHAAlg']) pub_exp = bytes_to_long(test_vector['e']) public_key = RSA.construct((modulus, pub_exp)) add_method_dict = { 'P': cls.add_positive_test, 'F': cls.add_negative_test } add_method = add_method_dict[test_vector['Result'][:1]] # In the test vector file, "00" indicates no salt salt = test_vector['SaltVal'] if salt == bchr(0): salt = b("") add_method(hashmod, test_vector['Msg'], public_key, salt, test_vector['S'])
def add_fips_tests(cls): file_tv = open_fips_test_file("PKCS1-v1.5", "SigVer15_186-3.rsp") sections = load_test_vector(file_tv, ('SHAAlg', 'd', 'Result')) modulus = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appear # in a single line if len(test_vector) == 1: modulus = bytes_to_long(test_vector['n']) continue hashmod = load_hash_by_name(test_vector['SHAAlg']) pub_exp = bytes_to_long(test_vector['e']) public_key = RSA.construct((modulus, pub_exp)) add_method_dict = {'P': cls.add_positive_test, 'F': cls.add_negative_test} add_method = add_method_dict[test_vector['Result']] add_method(hashmod, test_vector['Msg'], public_key, test_vector['S'])
def add_fips_tests(cls): file_tv = open_fips_test_file("PKCS1-PSS", "SigVerPSS_186-3.rsp") sections = load_test_vector(file_tv, ('SHAAlg', 'Result')) modulus = None for mod_size, test_vectors in sections.iteritems(): for test_vector in test_vectors: # The modulus for all subsequent test vectors appear # in a single line if len(test_vector) == 1: modulus = bytes_to_long(test_vector['n']) continue # p and q are not used if len(test_vector) == 2: continue hashmod = load_hash_by_name(test_vector['SHAAlg']) pub_exp = bytes_to_long(test_vector['e']) public_key = RSA.construct((modulus, pub_exp)) add_method_dict = {'P': cls.add_positive_test, 'F': cls.add_negative_test} add_method = add_method_dict[test_vector['Result'][:1]] # In the test vector file, "00" indicates no salt salt = test_vector['SaltVal'] if salt == bchr(0): salt = b("") add_method(hashmod, test_vector['Msg'], public_key, salt, test_vector['S'])