-
Notifications
You must be signed in to change notification settings - Fork 9
/
gencorp.py
58 lines (51 loc) · 3.35 KB
/
gencorp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# tool to generate corpus
import os
import binascii
curves = {
"secp192k1": (18, "FFFFFFFF FFFFFFFF FFFFFFFE 26F2FC17 0F69466A 74DEFD8C", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFEE37") ,
"secp192r1": (19, "FFFFFFFF FFFFFFFF FFFFFFFF 99DEF836 146BC9B1 B4D22830", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFFFF FFFFFFFF") ,
"secp224k1": (20, "00000000 00000000 00000000 0001DCE8 D2EC6184 CAF0A971 769FB1F6", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFE56D") ,
"secp224r1": (21, "FFFFFFFF FFFFFFFF FFFFFFFF FFFF16A2 E0B8F03E 13DD2945 5C5C2A3C", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 00000000 00000000 00000001") ,
"secp256k1": (22, "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364140", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F") ,
"secp256r1": (23, "FFFFFFFF 00000000 FFFFFFFF FFFFFFFF BCE6FAAD A7179E84 F3B9CAC2 FC632550", "FFFFFFFF 00000001 00000000 00000000 00000000 FFFFFFFF FFFFFFFF FFFFFFFF") ,
"secp384r1": (24, "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF C7634D81 F4372DDF 581A0DB2 48B0A77A ECEC196A CCC52972", "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFFFF 00000000 00000000 FFFFFFFF") ,
"secp521r1": (25, "01FF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFA 51868783 BF2F966B 7FCC0148 F709A5D0 3BB5C9B8 899C47AE BB6FB71E 91386408", "01FF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF") ,
"brainpoolP256r1": (26, "A9FB57DB A1EEA9BC 3E660A90 9D838D71 8C397AA3 B561A6F7 901E0E82 974856A6", "A9FB57DB A1EEA9BC 3E660A90 9D838D72 6E3BF623 D5262028 2013481D 1F6E5377") ,
"brainpoolP384r1": (27, "8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B3 1F166E6C AC0425A7 CF3AB6AF 6B7FC310 3B883202 E9046564", "8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B4 12B1DA19 7FB71123 ACD3A729 901D1A71 87470013 3107EC53") ,
"brainpoolP512r1": (28, "AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E D6639CCA 70330870 553E5C41 4CA92619 41866119 7FAC1047 1DB1D381 085DDADD B5879682 9CA90068", "AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E D6639CCA 70330871 7D4D9B00 9BC66842 AECDA12A E6A380E6 2881FF2F 2D82C685 28AA6056 583A48F3") ,
}
for c in curves:
tlsid, order, prime = curves[c]
order = order.replace(" ","")
prime = prime.replace(" ","")
#zero and identity double and triple
for s in [0,1,2,3]:
for y in [0, 1]:
for x in [0, 1, 2, 3]:
f = open("corpus/"+c+"0%d%d" % (x,y), "wb")
f.write(bytes([0, tlsid]))
f.write(bytes([0] * (len(order)-1)))
f.write(bytes([s, y]))
f.write(bytes([0] * (len(order)-1)))
f.write(bytes([x]))
f.close()
for i in range(10):
f = open("corpus/"+c+"random%d" % i, "wb")
f.write(bytes([0, tlsid]))
f.write(bytes(os.urandom(len(order)+1)))
f.close()
for i in range(10):
f = open("corpus/"+c+"minus%d" % i, "wb")
f.write(bytes([0, tlsid]))
f.write(binascii.unhexlify(order))
f.write(bytes([i]))
x=int(prime, 16)
x-=i+1
try:
xb = binascii.unhexlify("%x" % x)
except:
#ugly hack for odd length strings
xb = binascii.unhexlify("0%x" % x)
f.write(xb)
f.close()