def json_parametrize(keys, filename): vector_file = cryptography_vectors.open_vector_file( os.path.join("fernet", filename), "r") with vector_file: data = json.load(vector_file) return pytest.mark.parametrize( keys, [tuple([entry[k] for k in keys]) for entry in data])
def json_parametrize(keys, filename): vector_file = cryptography_vectors.open_vector_file('fernet', filename) with vector_file: data = json.load(vector_file) return pytest.mark.parametrize(keys, [ tuple([entry[k] for k in keys]) for entry in data ])
def load_vectors_from_file(filename, loader, mode="r"): with cryptography_vectors.open_vector_file(filename, mode) as vector_file: return loader(vector_file)
def load_vectors_from_file(filename, loader: typing.Callable[..., T], mode="r") -> T: with cryptography_vectors.open_vector_file(filename, mode) as vector_file: return loader(vector_file)
signature = secret_key.sign( message, hashfunc=hash_func, sigencode=sigencode_der ) r, s = sigdecode_der(signature, None) yield "Msg = {0}".format(hexlify(message)) yield "d = {0:x}".format(secret_key.privkey.secret_multiplier) yield "Qx = {0:x}".format(public_key.pubkey.point.x()) yield "Qy = {0:x}".format(public_key.pubkey.point.y()) yield "R = {0:x}".format(r) yield "S = {0:x}".format(s) yield "" def write_file(lines, dest): for line in lines: print(line) print(line, file=dest) source_path = os.path.join("asymmetric", "ECDSA", "FIPS_186-3", "SigGen.txt") dest_path = os.path.join("asymmetric", "ECDSA", "SECP256K1", "SigGen.txt") fips_vectors = load_vectors_from_file( source_path, load_fips_ecdsa_signing_vectors ) with open_vector_file(dest_path, "w") as dest_file: write_file(build_vectors(fips_vectors), dest_file)
r, s = sigdecode_der(signature, None) yield "Msg = {0}".format(hexlify(message)) yield "d = {0:x}".format(secret_key.privkey.secret_multiplier) yield "Qx = {0:x}".format(public_key.pubkey.point.x()) yield "Qy = {0:x}".format(public_key.pubkey.point.y()) yield "R = {0:x}".format(r) yield "S = {0:x}".format(s) yield "" def write_file(lines, dest): for line in lines: print(line) print(line, file=dest) source_path = os.path.join("asymmetric", "ECDSA", "FIPS_186-3", "SigGen.txt") dest_path = os.path.join("asymmetric", "ECDSA", "SECP256K1", "SigGen.txt") fips_vectors = load_vectors_from_file( source_path, load_fips_ecdsa_signing_vectors ) with open_vector_file(dest_path, "w") as dest_file: write_file( build_vectors(fips_vectors), dest_file )