Commit 03833f6
committed
Add CryptoCb support for LMS and XMSS
Groundwork for routing LMS / HSS (RFC 8554) and XMSS / XMSS^MT
(RFC 8391, both profiled in NIST SP 800-208) through the
WOLF_CRYPTO_CB framework so that the wolfSSL PKCS#11 provider and the
wolfHSM client can later host stateful hash-based keys on a device.
No HSM-side or PKCS#11-provider code is in scope; this commit only
adds the wolfSSL-side dispatcher layer, the per-key device binding,
and the helpers a backend needs to answer the request.
Dispatcher surface (modelled on wc_CryptoCb_PqcSign* used for
Dilithium and Falcon):
WC_PK_TYPE_PQC_STATEFUL_SIG_KEYGEN
WC_PK_TYPE_PQC_STATEFUL_SIG_SIGN
WC_PK_TYPE_PQC_STATEFUL_SIG_VERIFY
WC_PK_TYPE_PQC_STATEFUL_SIG_SIGS_LEFT
A new discriminator enum wc_PqcStatefulSignatureType
(WC_PQC_STATEFUL_SIG_TYPE_LMS / _XMSS) tells the callback how to
interpret the void* key. The dispatcher functions are
wc_CryptoCb_PqcStatefulSig{KeyGen,Sign,Verify,SigsLeft} plus the
wc_CryptoCb_PqcStatefulSigGetDevId helper. XMSS vs XMSS^MT is
discriminated inside the callback via the existing
XmssKey::is_xmssmt field.
Mapping to PKCS#11 v3.1 / v3.2:
wc_LmsKey_MakeKey -> CKM_HSS_KEY_PAIR_GEN
wc_LmsKey_Sign -> CKM_HSS (sign)
wc_LmsKey_Verify -> CKM_HSS (verify)
wc_LmsKey_SigsLeft -> CKA_HSS_KEYS_REMAINING attribute
wc_XmssKey_MakeKey -> CKM_XMSS_KEY_PAIR_GEN / CKM_XMSSMT_KEY_PAIR_GEN
wc_XmssKey_Sign -> CKM_XMSS / CKM_XMSSMT (sign)
wc_XmssKey_Verify -> CKM_XMSS / CKM_XMSSMT (verify)
wc_XmssKey_SigsLeft -> XMSS remaining-sigs attribute
Public API additions:
- LmsKey / XmssKey gain (under WOLF_CRYPTO_CB) int devId and
void* devCtx, and (under WOLF_PRIVATE_KEY_ID) byte id[],
int idLen, char label[], int labelLen, with LMS_MAX_ID_LEN,
LMS_MAX_LABEL_LEN, XMSS_MAX_ID_LEN, XMSS_MAX_LABEL_LEN constants
defaulting to 32 and overridable.
- wc_LmsKey_InitId / wc_LmsKey_InitLabel and the XMSS equivalents,
gated on WOLF_PRIVATE_KEY_ID, mirror wc_InitRsaKey_Id /
wc_InitRsaKey_Label.
- wc_LmsKey_HashMsg / wc_XmssKey_HashMsg compute the digest dictated
by the parameter set (SHA-256 / SHA-256-192 / SHAKE256 / SHAKE256-192
for LMS; SHA-256 / SHA-512 / SHAKE128 / SHAKE256 for XMSS) so a
PKCS#11-style backend can produce the digest from inside the
callback. wolfHSM-style backends ignore the helper and consume
msg / msgSz directly.
Behaviour notes:
- The CryptoCb dispatch in wc_*Key_MakeKey / Sign runs before the
software write/read/context callback validation so a device-backed
key does not need dummy software callbacks. On CRYPTOCB_UNAVAILABLE
the software validations are re-applied.
- wc_*Key_Verify rejects negative msgSz before widening to word32 for
the dispatcher, and surfaces validity through int* res in the
dispatcher, translating res != 1 back to SIG_VERIFY_E for the
wolfSSL caller.
- wc_*Key_SigsLeft uses word32* sigsLeft so a key at the 2^32 PKCS#11
limit can be expressed unambiguously; the public int-returning API
clamps at 0x7FFFFFFF and emits WOLFSSL_MSG instead of swallowing
device errors.
- wc_*Key_Reload short-circuits for HSM-backed keys; wc_LmsKey_GetKid
warns that priv_raw may be uninitialised; wc_*Key_ExportPub
preserves the source key's devId so the verify-only copy keeps
dispatching through the same device.
Test coverage:
myCryptoDevCb gains four new handlers that bounce each operation
back into the software API by clearing devId and restoring it; both
Sign and Verify go through the dispatcher, so the produced signatures
self-verify within the harness. lms_test and xmss_test are invoked
inside cryptocb_test to exercise the full round trip.
Builds verified:
--enable-lms --enable-xmss --enable-cryptocb (primary)
--enable-lms --enable-xmss --enable-cryptocb CPPFLAGS=-DWOLF_PRIVATE_KEY_ID
--enable-lms --enable-xmss
--enable-cryptocb
A doc/LMS_XMSS_CryptoCb.md document covers the rationale, the
PKCS#11 mapping, the public API, and the design notes.1 parent 3181e2b commit 03833f6
11 files changed
Lines changed: 1063 additions & 5 deletions
File tree
- doc
- wolfcrypt
- src
- test
- wolfssl/wolfcrypt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1017 | 1017 | | |
1018 | 1018 | | |
1019 | 1019 | | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
1020 | 1168 | | |
1021 | 1169 | | |
1022 | 1170 | | |
| |||
0 commit comments