|
8 | 8 | " * This file has been generated and contains the public key which is\n"+ \ |
9 | 9 | " * used by wolfBoot to verify the updates.\n"+ \ |
10 | 10 | " */" \ |
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" |
13 | 15 |
|
14 | 16 | sign="ed25519" |
15 | 17 |
|
|
57 | 59 | print("Creating file " + pubkey_cfile) |
58 | 60 | with open(pubkey_cfile, "w") as f: |
59 | 61 | f.write(Cfile_Banner) |
| 62 | + f.write(Ed25519_pub_key_define) |
60 | 63 | i = 0 |
61 | 64 | for c in bytes(pub[0:-1]): |
62 | 65 | f.write("0x%02X, " % c) |
63 | 66 | i += 1 |
64 | 67 | if (i % 8 == 0): |
65 | | - f.write('\n') |
| 68 | + f.write('\n\t') |
66 | 69 | f.write("0x%02X" % pub[-1]) |
67 | 70 | f.write("\n};\n") |
68 | 71 | f.write("const uint32_t ed25519_pub_key_len = 32;\n") |
69 | 72 | f.close() |
70 | 73 |
|
71 | 74 | 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() |
74 | 77 | if os.path.exists(key_file): |
75 | 78 | choice = input("** Warning: key file already exist! Are you sure you want to "+ |
76 | 79 | "generate a new key and overwrite the existing key? [Type 'Yes, I am sure!']: ") |
|
81 | 84 | print() |
82 | 85 | print("Creating file " + key_file) |
83 | 86 | 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") |
85 | 109 | f.close() |
86 | 110 |
|
87 | 111 |
|
0 commit comments