Skip to content

Commit 17f382b

Browse files
committed
Fixed ECC in keygen.py (requires latest wolfcrypt-py)
1 parent 91cacce commit 17f382b

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

tools/keytools/keygen.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
" * This file has been generated and contains the public key which is\n"+ \
99
" * used by wolfBoot to verify the updates.\n"+ \
1010
" */" \
11-
"\n#include <stdint.h>\n\n" + \
12-
"const uint8_t ed25519_pub_key[32] = {\n"
11+
"\n#include <stdint.h>\n\n"
12+
13+
Ed25519_pub_key_define = "const uint8_t ed25519_pub_key[32] = {\n\t"
14+
Ecc256_pub_key_define = "const uint8_t ecc256_pub_key[64] = {\n\t"
1315

1416
sign="ed25519"
1517

@@ -57,20 +59,21 @@
5759
print("Creating file " + pubkey_cfile)
5860
with open(pubkey_cfile, "w") as f:
5961
f.write(Cfile_Banner)
62+
f.write(Ed25519_pub_key_define)
6063
i = 0
6164
for c in bytes(pub[0:-1]):
6265
f.write("0x%02X, " % c)
6366
i += 1
6467
if (i % 8 == 0):
65-
f.write('\n')
68+
f.write('\n\t')
6669
f.write("0x%02X" % pub[-1])
6770
f.write("\n};\n")
6871
f.write("const uint32_t ed25519_pub_key_len = 32;\n")
6972
f.close()
7073

7174
if (sign == "ecc256"):
72-
ec = ciphers.EccPrivate.make_key(64)
73-
priv = ec.encode_key()
75+
ec = ciphers.EccPrivate.make_key(32)
76+
qx,qy,d = ec.encode_key_raw()
7477
if os.path.exists(key_file):
7578
choice = input("** Warning: key file already exist! Are you sure you want to "+
7679
"generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ")
@@ -81,7 +84,28 @@
8184
print()
8285
print("Creating file " + key_file)
8386
with open(key_file, "wb") as f:
84-
f.write(priv)
87+
f.write(qx)
88+
f.write(qy)
89+
f.write(d)
90+
f.close()
91+
print("Creating file " + pubkey_cfile)
92+
with open(pubkey_cfile, "w") as f:
93+
f.write(Cfile_Banner)
94+
f.write(Ecc256_pub_key_define)
95+
i = 0
96+
for c in bytes(qx):
97+
f.write("0x%02X, " % c)
98+
i += 1
99+
if (i % 8 == 0):
100+
f.write('\n')
101+
for c in bytes(qy[0:-1]):
102+
f.write("0x%02X, " % c)
103+
i += 1
104+
if (i % 8 == 0):
105+
f.write('\n')
106+
f.write("0x%02X" % qy[-1])
107+
f.write("\n};\n")
108+
f.write("const uint32_t ed25519_pub_key_len = 64;\n")
85109
f.close()
86110

87111

0 commit comments

Comments
 (0)