@@ -1048,7 +1048,29 @@ int wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce);
10481048int wolfBoot_erase_encrypt_key(void); /* called automatically by wolfBoot_success() * /
10491049```
10501050
1051- To use your own implementation for getting the encryption key use `CUSTOM_ENCRYPT_KEY` and `OBJS_EXTRA=src/my_custom_encrypt_key.o`. Then provide your own implementation of `int wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce);`
1051+ To use your own implementation for getting the encryption key use `CUSTOM_ENCRYPT_KEY` and `OBJS_EXTRA=src/my_custom_encrypt_key.o`.
1052+ Then provide your own implementation of `int RAMFUNCTION wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce);`
1053+
1054+ Example:
1055+
1056+ ```c
1057+ int RAMFUNCTION wolfBoot_get_encrypt_key(uint8_t *key, uint8_t *nonce)
1058+ {
1059+ int i;
1060+ /* Test key: "0123456789abcdef0123456789abcdef" (32 bytes for AES-256) */
1061+ const char test_key[] = "0123456789abcdef0123456789abcdef";
1062+ /* Test nonce: "0123456789abcdef" (16 bytes) */
1063+ const char test_nonce[] = "0123456789abcdef";
1064+
1065+ for (i = 0; i < ENCRYPT_KEY_SIZE && i < (int)sizeof(test_key); i++) {
1066+ key[i] = (uint8_t)test_key[i];
1067+ }
1068+ for (i = 0; i < ENCRYPT_NONCE_SIZE && i < (int)sizeof(test_nonce); i++) {
1069+ nonce[i] = (uint8_t)test_nonce[i];
1070+ }
1071+ return 0;
1072+ }
1073+ ```
10521074
10531075To sign and encrypt an image, create a key file with the concatenated key and nonce, then use the sign tool:
10541076
@@ -1063,10 +1085,74 @@ printf "0123456789abcdef0123456789abcdef0123456789abcdef" > /tmp/enc_key.der
10631085
10641086The result is ` fitImage_v1_signed_and_encrypted.bin ` , which gets placed into your OFP_A or OFP_B partitions.
10651087
1088+ ``` sh
1089+ sudo dd if=fitImage_v1_signed_and_encrypted.bin of=/dev/sdc2 bs=512 status=progress && sudo cmp fitImage_v1_signed_and_encrypted.bin /dev/sdc2
1090+ sudo dd if=fitImage_v1_signed_and_encrypted.bin of=/dev/sdc3 bs=512 status=progress && sudo cmp fitImage_v1_signed_and_encrypted.bin /dev/sdc3
1091+ ```
1092+
10661093During boot, wolfBoot decrypts the image headers from disk to select the best candidate, loads and decrypts the full image to RAM, then verifies integrity and authenticity before booting. On successful boot, ` wolfBoot_success() ` clears the key from RAM.
10671094
10681095See the [ Encrypted Partitions] ( encrypted_partitions.md ) documentation for additional details.
10691096
1097+ ### PolarFire SoC with PQC (ML-DSA)
1098+
1099+ #### Configuration
1100+
1101+ Update your ` .config ` file with the following ML-DSA settings:
1102+
1103+ ``` makefile
1104+ # ML-DSA 87 (Category 5)
1105+ SIGN =ML_DSA
1106+ HASH =SHA256
1107+ ML_DSA_LEVEL =5
1108+ IMAGE_SIGNATURE_SIZE =4627
1109+ IMAGE_HEADER_SIZE =12288
1110+ WOLFBOOT_SECTOR_SIZE? =0x4000
1111+ ```
1112+
1113+ ** Important:**
1114+ - The ` sign ` tool requires ` IMAGE_HEADER_SIZE ` to be set as an environment variable, even if it's already configured in ` .config ` . This is because the sign tool reads the environment variable separately to determine the header size for padding. Without this, the sign tool may use a smaller default header size, causing a mismatch with wolfBoot's expected header size.
1115+ - The ` WOLFBOOT_SECTOR_SIZE ` must be larger than the ` IMAGE_HEADER_SIZE ` /
1116+
1117+ #### Signing and Encryption
1118+
1119+ ``` sh
1120+ # Sign and Encrypt with PQ ML-DSA 5 (87)
1121+ # NOTE: IMAGE_HEADER_SIZE must match the value in .config
1122+ IMAGE_HEADER_SIZE=12288 ML_DSA_LEVEL=5 ./tools/keytools/sign --ml_dsa --sha256 --aes256 --encrypt /tmp/enc_key.der \
1123+ fitImage wolfboot_signing_private_key.der 1
1124+ ```
1125+
1126+ ** ML-DSA Parameter Reference:**
1127+
1128+ | ML_DSA_LEVEL | Security Category | Signature Size | Private Key | Public Key | Recommended IMAGE_HEADER_SIZE |
1129+ | --------------| -------------------| ----------------| -------------| ------------| ------------------------------ |
1130+ | 2 | Category 2 | 2420 | 2560 | 1312 | 8192 |
1131+ | 3 | Category 3 | 3309 | 4032 | 1952 | 8192 |
1132+ | 5 | Category 5 | 4627 | 4896 | 2592 | 12288 |
1133+
1134+ For other ML-DSA levels, adjust ` ML_DSA_LEVEL ` , ` IMAGE_SIGNATURE_SIZE ` , and ` IMAGE_HEADER_SIZE ` accordingly in both ` .config ` and the signing command.
1135+
1136+ ### PolarFire Performance Comparison
1137+
1138+ #### Binary Size Comparison
1139+
1140+ The following table compares wolfBoot binary sizes for different signature algorithms on PolarFire SoC (MPFS250):
1141+
1142+ | Algorithm | Hash | Text | Data | BSS | Total | Binary Size |
1143+ | -----------| --------| ---------| ------| ---------| ---------| -------------|
1144+ | ECC384 | SHA384 | 67.1 KB | 8 B | 3.0 KB | 70.2 KB | 68 KB |
1145+ | ML-DSA 87 | SHA256 | 63.9 KB | 0 B | 14.5 KB | 78.4 KB | 64 KB |
1146+
1147+ #### Boot Time Comparison
1148+
1149+ Boot time measurements on PolarFire SoC (RISC-V 64-bit U54 @ 625 MHz) for a 19MB encrypted FIT image:
1150+
1151+ | Algorithm | Hash | Load Time | Decrypt Time | Integrity Check | Signature Verify | Total Boot Time |
1152+ | -------------| ---------| -----------| --------------| -----------------| ------------------| -----------------|
1153+ | ECC384 | SHA384 | ~ 800 ms | ~ 2900 ms | ~ 1500 ms | ~ 70 ms | ~ 5.3 seconds |
1154+ | ML-DSA 87 | SHA256 | ~ 835 ms | ~ 2900 ms | ~ 2100 ms | ~ 22 ms | ~ 5.9 seconds |
1155+
10701156### PolarFire Soc Debugging
10711157
10721158Start GDB server:
@@ -1154,48 +1240,80 @@ FDT: MAC1 = 00:04:A3:5B:22:89
11541240RISC-V 64-bit U54 (RV64GC1) 625 MHz
11551241
11561242```
1243+ ./configure --enable-riscv-asm --enable-dilithium --enable-mlkem --enable-sp=yes
1244+ make
1245+ ./wolfcrypt/benchmark/benchmark
11571246------------------------------------------------------------------------------
11581247 wolfSSL version 5.8.4
11591248------------------------------------------------------------------------------
11601249Math: Multi-Precision: Wolf(SP) word-size=64 bits=3072 sp_int.c
1250+ Single Precision: ecc 256 rsa/dh 2048 3072 sp_c64.c
11611251 Assembly Speedups: RISCVASM ALIGN
11621252wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
1163- RNG 5 MiB took 1.232 seconds, 4.058 MiB/s
1164- AES-128-CBC-enc 10 MiB took 1.182 seconds, 8.457 MiB/s
1165- AES-128-CBC-dec 10 MiB took 1.166 seconds, 8.573 MiB/s
1166- AES-192-CBC-enc 10 MiB took 1.378 seconds, 7.257 MiB/s
1167- AES-192-CBC-dec 10 MiB took 1.362 seconds, 7.344 MiB/s
1168- AES-256-CBC-enc 10 MiB took 1.569 seconds, 6.373 MiB/s
1169- AES-256-CBC-dec 10 MiB took 1.556 seconds, 6.426 MiB/s
1170- AES-128-GCM-enc 10 MiB took 1.956 seconds, 5.113 MiB/s
1171- AES-128-GCM-dec 10 MiB took 1.955 seconds, 5.115 MiB/s
1172- AES-192-GCM-enc 5 MiB took 1.075 seconds, 4.650 MiB/s
1173- AES-192-GCM-dec 5 MiB took 1.074 seconds, 4.654 MiB/s
1174- AES-256-GCM-enc 5 MiB took 1.172 seconds, 4.268 MiB/s
1175- AES-256-GCM-dec 5 MiB took 1.170 seconds, 4.275 MiB/s
1176- GMAC Table 4-bit 15 MiB took 1.133 seconds, 13.245 MiB/s
1177- CHACHA 20 MiB took 1.107 seconds, 18.064 MiB/s
1178- CHA-POLY 15 MiB took 1.060 seconds, 14.152 MiB/s
1179- POLY1305 75 MiB took 1.044 seconds, 71.812 MiB/s
1180- SHA 20 MiB took 1.139 seconds, 17.561 MiB/s
1181- SHA-256 10 MiB took 1.069 seconds, 9.350 MiB/s
1182- SHA-384 15 MiB took 1.072 seconds, 13.994 MiB/s
1183- SHA-512 15 MiB took 1.072 seconds, 13.990 MiB/s
1184- SHA-512/224 15 MiB took 1.068 seconds, 14.041 MiB/s
1185- SHA-512/256 15 MiB took 1.066 seconds, 14.070 MiB/s
1186- HMAC-SHA 20 MiB took 1.140 seconds, 17.542 MiB/s
1187- HMAC-SHA256 10 MiB took 1.068 seconds, 9.366 MiB/s
1188- HMAC-SHA384 15 MiB took 1.066 seconds, 14.076 MiB/s
1189- HMAC-SHA512 15 MiB took 1.066 seconds, 14.077 MiB/s
1190- PBKDF2 1 KiB took 1.024 seconds, 1.129 KiB/s
1191- RSA 2048 public 800 ops took 1.142 sec, avg 1.427 ms, 700.575 ops/sec
1192- RSA 2048 private 100 ops took 8.450 sec, avg 84.504 ms, 11.834 ops/sec
1193- DH 2048 key gen 60 ops took 1.010 sec, avg 16.841 ms, 59.379 ops/sec
1194- DH 2048 agree 100 ops took 3.421 sec, avg 34.211 ms, 29.231 ops/sec
1195- ECC [ SECP256R1] 256 key gen 100 ops took 1.304 sec, avg 13.039 ms, 76.691 ops/sec
1196- ECDHE [ SECP256R1] 256 agree 100 ops took 1.299 sec, avg 12.992 ms, 76.970 ops/sec
1197- ECDSA [ SECP256R1] 256 sign 100 ops took 1.338 sec, avg 13.383 ms, 74.723 ops/sec
1198- ECDSA [ SECP256R1] 256 verify 200 ops took 1.846 sec, avg 9.231 ms, 108.333 ops/sec
1253+ RNG 5 MiB took 1.225 seconds, 4.081 MiB/s
1254+ AES-128-CBC-enc 10 MiB took 1.179 seconds, 8.478 MiB/s
1255+ AES-128-CBC-dec 10 MiB took 1.164 seconds, 8.589 MiB/s
1256+ AES-192-CBC-enc 10 MiB took 1.373 seconds, 7.281 MiB/s
1257+ AES-192-CBC-dec 10 MiB took 1.360 seconds, 7.354 MiB/s
1258+ AES-256-CBC-enc 10 MiB took 1.565 seconds, 6.389 MiB/s
1259+ AES-256-CBC-dec 10 MiB took 1.550 seconds, 6.451 MiB/s
1260+ AES-128-GCM-enc 10 MiB took 1.940 seconds, 5.156 MiB/s
1261+ AES-128-GCM-dec 10 MiB took 1.938 seconds, 5.159 MiB/s
1262+ AES-192-GCM-enc 5 MiB took 1.068 seconds, 4.680 MiB/s
1263+ AES-192-GCM-dec 5 MiB took 1.066 seconds, 4.689 MiB/s
1264+ AES-256-GCM-enc 5 MiB took 1.163 seconds, 4.298 MiB/s
1265+ AES-256-GCM-dec 5 MiB took 1.163 seconds, 4.301 MiB/s
1266+ GMAC Table 4-bit 15 MiB took 1.106 seconds, 13.566 MiB/s
1267+ CHACHA 20 MiB took 1.107 seconds, 18.068 MiB/s
1268+ CHA-POLY 15 MiB took 1.058 seconds, 14.178 MiB/s
1269+ POLY1305 75 MiB took 1.036 seconds, 72.387 MiB/s
1270+ SHA 20 MiB took 1.141 seconds, 17.535 MiB/s
1271+ SHA-256 10 MiB took 1.071 seconds, 9.336 MiB/s
1272+ SHA-384 15 MiB took 1.066 seconds, 14.068 MiB/s
1273+ SHA-512 15 MiB took 1.066 seconds, 14.070 MiB/s
1274+ SHA-512/224 15 MiB took 1.067 seconds, 14.060 MiB/s
1275+ SHA-512/256 15 MiB took 1.070 seconds, 14.023 MiB/s
1276+ SHA3-224 15 MiB took 1.328 seconds, 11.292 MiB/s
1277+ SHA3-256 15 MiB took 1.398 seconds, 10.731 MiB/s
1278+ SHA3-384 10 MiB took 1.206 seconds, 8.291 MiB/s
1279+ SHA3-512 10 MiB took 1.729 seconds, 5.785 MiB/s
1280+ SHAKE128 15 MiB took 1.142 seconds, 13.135 MiB/s
1281+ SHAKE256 15 MiB took 1.402 seconds, 10.699 MiB/s
1282+ HMAC-SHA 20 MiB took 1.145 seconds, 17.470 MiB/s
1283+ HMAC-SHA256 10 MiB took 1.074 seconds, 9.310 MiB/s
1284+ HMAC-SHA384 15 MiB took 1.076 seconds, 13.944 MiB/s
1285+ HMAC-SHA512 15 MiB took 1.069 seconds, 14.036 MiB/s
1286+ PBKDF2 1 KiB took 1.023 seconds, 1.130 KiB/s
1287+ RSA 2048 public 1000 ops took 1.087 sec, avg 1.087 ms, 920.244 ops/sec
1288+ RSA 2048 private 100 ops took 5.410 sec, avg 54.100 ms, 18.484 ops/sec
1289+ DH 2048 key gen 48 ops took 1.004 sec, avg 20.920 ms, 47.801 ops/sec
1290+ DH 2048 agree 100 ops took 2.087 sec, avg 20.873 ms, 47.909 ops/sec
1291+ ECC [ SECP256R1] 256 key gen 800 ops took 1.100 sec, avg 1.375 ms, 727.248 ops/sec
1292+ ECDHE [ SECP256R1] 256 agree 300 ops took 1.041 sec, avg 3.470 ms, 288.152 ops/sec
1293+ ECDSA [ SECP256R1] 256 sign 600 ops took 1.144 sec, avg 1.907 ms, 524.370 ops/sec
1294+ ECDSA [ SECP256R1] 256 verify 300 ops took 1.173 sec, avg 3.909 ms, 255.844 ops/sec
1295+ ECC [ SECP384R1] 384 key gen 100 ops took 3.887 sec, avg 38.867 ms, 25.729 ops/sec
1296+ ECDHE [ SECP384R1] 384 agree 100 ops took 3.883 sec, avg 38.827 ms, 25.755 ops/sec
1297+ ECDSA [ SECP384R1] 384 sign 100 ops took 3.948 sec, avg 39.485 ms, 25.326 ops/sec
1298+ ECDSA [ SECP384R1] 384 verify 100 ops took 2.619 sec, avg 26.190 ms, 38.183 ops/sec
1299+ ML-KEM 512 128 key gen 2000 ops took 1.021 sec, avg 0.511 ms, 1958.111 ops/sec
1300+ ML-KEM 512 128 encap 1700 ops took 1.006 sec, avg 0.592 ms, 1690.275 ops/sec
1301+ ML-KEM 512 128 decap 1300 ops took 1.075 sec, avg 0.827 ms, 1209.214 ops/sec
1302+ ML-KEM 768 192 key gen 1200 ops took 1.035 sec, avg 0.863 ms, 1158.970 ops/sec
1303+ ML-KEM 768 192 encap 1100 ops took 1.092 sec, avg 0.993 ms, 1006.925 ops/sec
1304+ ML-KEM 768 192 decap 800 ops took 1.055 sec, avg 1.319 ms, 758.026 ops/sec
1305+ ML-KEM 1024 256 key gen 800 ops took 1.124 sec, avg 1.405 ms, 711.862 ops/sec
1306+ ML-KEM 1024 256 encap 700 ops took 1.090 sec, avg 1.557 ms, 642.343 ops/sec
1307+ ML-KEM 1024 256 decap 600 ops took 1.181 sec, avg 1.968 ms, 508.073 ops/sec
1308+ ML-DSA 44 key gen 600 ops took 1.107 sec, avg 1.844 ms, 542.217 ops/sec
1309+ ML-DSA 44 sign 200 ops took 1.144 sec, avg 5.719 ms, 174.842 ops/sec
1310+ ML-DSA 44 verify 600 ops took 1.146 sec, avg 1.910 ms, 523.569 ops/sec
1311+ ML-DSA 65 key gen 400 ops took 1.267 sec, avg 3.167 ms, 315.744 ops/sec
1312+ ML-DSA 65 sign 200 ops took 1.687 sec, avg 8.436 ms, 118.543 ops/sec
1313+ ML-DSA 65 verify 400 ops took 1.272 sec, avg 3.180 ms, 314.428 ops/sec
1314+ ML-DSA 87 key gen 200 ops took 1.066 sec, avg 5.331 ms, 187.588 ops/sec
1315+ ML-DSA 87 sign 100 ops took 1.162 sec, avg 11.617 ms, 86.084 ops/sec
1316+ ML-DSA 87 verify 200 ops took 1.077 sec, avg 5.385 ms, 185.704 ops/sec
11991317Benchmark complete
12001318```
12011319
0 commit comments