Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
Script to load NIST SP800-90A Dual_EC_DRBG curve parameters into Python.
Requires Python 3.
Henry de Valence <>
def hexi(s):
# python is picky about having 2 chars / byte, so pad zeros.
input = s.replace(' ','')
padded = '0'*(len(input) % 2) + input
return int.from_bytes(bytearray.fromhex(padded), byteorder='big')
p256 = { 'p' : 115792089210356248762697446949407573530086143415290314195533631308867097853951
, 'n' : 115792089210356248762697446949407573529996955224135760342422259061068512044369
, 'b' : hexi('5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b')
, 'Px': hexi('6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296')
, 'Py': hexi('4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5')
, 'Qx': hexi('c97445f4 5cdef9f0 d3e05e1e 585fc297 235b82b5 be8ff3ef ca67c598 52018192')
, 'Qy': hexi('b28ef557 ba31dfcb dd21ac46 e2a91e3c 304f44cb 87058ada 2cb81515 1e610046')
p384 = { 'p' : 39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319
, 'n' : 39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643
, 'b' : hexi('b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef')
, 'Px': hexi('aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7')
, 'Py': hexi('3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f')
, 'Qx': hexi('8e722de3 125bddb0 5580164b fe20b8b4 32216a62 926c5750 2ceede31 c47816ed d1e89769 124179d0 b6951064 28815065')
, 'Qy': hexi('023b1660 dd701d08 39fd45ee c36f9ee7 b32e13b3 15dc0261 0aa1b636 e346df67 1f790f84 c5e09b05 674dbb7e 45c803dd')
p521 = { 'p' : 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151
, 'n' : 6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449
, 'b' : hexi('051953eb 9618e1c9 a1f929a2 1a0b6854 0eea2da7 25b99b31 5f3b8b48 9918ef10 9e156193 951ec7e9 37b1652c 0bd3bb1b f073573d f883d2c3 4f1ef451 fd46b503 f00')
, 'Px': hexi('c6858e06 b70404e9 cd9e3ecb 662395b4 429c6481 39053fb5 21f828af 606b4d3d baa14b5e 77efe759 28fe1dc1 27a2ffa8 de3348b3 c1856a42 9bf97e7e 31c2e5bd 66')
, 'Py': hexi('11839296 a789a3bc 0045c8a5 fb42c7d1 bd998f54 449579b4 46817afb d17273e6 62c97ee7 2995ef42 640c550b 9013fad0 761353c7 086a272c 24088be9 4769fd16 650')
, 'Qx': hexi('1b9fa3e5 18d683c6 b6576369 4ac8efba ec6fab44 f2276171 a4272650 7dd08add 4c3b3f4c 1ebc5b12 22ddba07 7f722943 b24c3edf a0f85fe2 4d0c8c01 591f0be6 f63')
, 'Qy': hexi('1f3bdba5 85295d9a 1110d1df 1f9430ef 8442c501 8976ff34 37ef91b8 1dc0b813 2c8d5c39 c32d0e00 4a3092b7 d327c0e7 a4d26d2c 7b69b58f 90666529 11e45777 9de')
if __name__=='__main__':
for c in [p256, p384, p521]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.