| 1 |
/************************************************************************* |
| 2 |
* Copyright (C) 2023 Intel Corporation |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*************************************************************************/ |
| 16 |
|
| 17 |
#include "owndefs.h" |
| 18 |
#include "stateful_sig/xmss_internal/xmss.h" |
| 19 |
|
| 20 |
/*F* |
| 21 |
// Name: ippsXMSSSetPublicKeyState |
| 22 |
// |
| 23 |
// Purpose: Set XMSS public key. |
| 24 |
// |
| 25 |
// Returns: Reason: |
| 26 |
// ippStsNullPtrErr pRoot == NULL |
| 27 |
// pSeed == NULL |
| 28 |
// pState == NULL |
| 29 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 30 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 31 |
// ippStsNoErr no errors |
| 32 |
// |
| 33 |
// Parameters: |
| 34 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 35 |
// pRoot pointer to the XMSS public key root |
| 36 |
// pSeed pointer to the XMSS public key seed |
| 37 |
// pState pointer to the XMSS public key state |
| 38 |
// |
| 39 |
*F*/ |
| 40 |
|
| 41 |
/* clang-format off */ |
| 42 |
IPPFUN(IppStatus, ippsXMSSSetPublicKeyState, (IppsXMSSAlgo OIDAlgo, |
| 43 |
const Ipp8u* pRoot, |
| 44 |
const Ipp8u* pSeed, |
| 45 |
IppsXMSSPublicKeyState* pState)) |
| 46 |
/* clang-format on */ |
| 47 |
{ |
| 48 |
IPP_BAD_PTR1_RET(pRoot); |
| 49 |
IPP_BAD_PTR1_RET(pSeed); |
| 50 |
IPP_BAD_PTR1_RET(pState); |
| 51 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 52 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 53 |
IppStatus status = ippStsNoErr; |
| 54 |
cpWOTSParams params; |
| 55 |
Ipp32s h = 0; |
| 56 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 57 |
Ipp32s n = params.n; |
| 58 |
|
| 59 |
pState->OIDAlgo = OIDAlgo; |
| 60 |
|
| 61 |
Ipp8u* ptr = (Ipp8u*)pState; |
| 62 |
|
| 63 |
/* allocate internal contexts */ |
| 64 |
ptr += sizeof(IppsXMSSPublicKeyState); |
| 65 |
|
| 66 |
pState->pRoot = ptr; |
| 67 |
CopyBlock(pRoot, pState->pRoot, n); |
| 68 |
ptr += n; |
| 69 |
|
| 70 |
pState->pSeed = ptr; |
| 71 |
CopyBlock(pSeed, pState->pSeed, n); |
| 72 |
|
| 73 |
return status; |
| 74 |
} |
| 75 |
|
| 76 |
/*F* |
| 77 |
// Name: ippsXMSSSetSignatureState |
| 78 |
// |
| 79 |
// Purpose: Set XMSS signature. |
| 80 |
// |
| 81 |
// Returns: Reason: |
| 82 |
// ippStsNullPtrErr r == NULL |
| 83 |
// pOTSSign == NULL |
| 84 |
// pAuthPath == NULL |
| 85 |
// pState == NULL |
| 86 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 87 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 88 |
// ippStsNoErr no errors |
| 89 |
// |
| 90 |
// Parameters: |
| 91 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 92 |
// idx index of XMSS leaf |
| 93 |
// r pointer to the XMSS signature randomness variable |
| 94 |
// pOTSSign pointer to the WOTS signature |
| 95 |
// pAuthPath pointer to the XMSS authorization path |
| 96 |
// pState pointer to the XMSS signature state |
| 97 |
// |
| 98 |
*F*/ |
| 99 |
|
| 100 |
/* clang-format off */ |
| 101 |
IPPFUN(IppStatus, ippsXMSSSetSignatureState, (IppsXMSSAlgo OIDAlgo, |
| 102 |
Ipp32u idx, |
| 103 |
const Ipp8u* r, |
| 104 |
const Ipp8u* pOTSSign, |
| 105 |
const Ipp8u* pAuthPath, |
| 106 |
IppsXMSSSignatureState* pState)) |
| 107 |
/* clang-format on */ |
| 108 |
{ |
| 109 |
IPP_BAD_PTR1_RET(r); |
| 110 |
IPP_BAD_PTR1_RET(pOTSSign); |
| 111 |
IPP_BAD_PTR1_RET(pAuthPath); |
| 112 |
IPP_BAD_PTR1_RET(pState); |
| 113 |
|
| 114 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 115 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 116 |
IppStatus status = ippStsNoErr; |
| 117 |
cpWOTSParams params; |
| 118 |
Ipp32s h = 0; |
| 119 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 120 |
Ipp32s n = params.n; |
| 121 |
Ipp32s len = params.len; |
| 122 |
|
| 123 |
pState->idx = idx; |
| 124 |
Ipp8u* ptr = (Ipp8u*)pState; |
| 125 |
|
| 126 |
/* allocate internal contexts */ |
| 127 |
ptr += sizeof(IppsXMSSSignatureState); |
| 128 |
|
| 129 |
pState->r = ptr; |
| 130 |
CopyBlock(r, pState->r, n); |
| 131 |
ptr += n; |
| 132 |
|
| 133 |
pState->pOTSSign = ptr; |
| 134 |
CopyBlock(pOTSSign, pState->pOTSSign, len * n); |
| 135 |
ptr += len * n; |
| 136 |
|
| 137 |
pState->pAuthPath = ptr; |
| 138 |
CopyBlock(pAuthPath, pState->pAuthPath, h * n); |
| 139 |
|
| 140 |
return status; |
| 141 |
} |
| 142 |
|
| 143 |
/*F* |
| 144 |
// Name: ippsXMSSSignatureStateGetSize |
| 145 |
// |
| 146 |
// Purpose: Get the XMSS signature state size (bytes). |
| 147 |
// |
| 148 |
// Returns: Reason: |
| 149 |
// ippStsNullPtrErr pSize == NULL |
| 150 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 151 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 152 |
// ippStsNoErr no errors |
| 153 |
// |
| 154 |
// Parameters: |
| 155 |
// pSize pointer to the size |
| 156 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 157 |
// |
| 158 |
*F*/ |
| 159 |
|
| 160 |
IPPFUN(IppStatus, ippsXMSSSignatureStateGetSize, (Ipp32s * pSize, IppsXMSSAlgo OIDAlgo)) |
| 161 |
{ |
| 162 |
IPP_BAD_PTR1_RET(pSize); |
| 163 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 164 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 165 |
IppStatus status = ippStsNoErr; |
| 166 |
cpWOTSParams params; |
| 167 |
Ipp32s h = 0; |
| 168 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 169 |
Ipp32s n = params.n; |
| 170 |
Ipp32s len = params.len; |
| 171 |
|
| 172 |
*pSize = (Ipp32s)sizeof(IppsXMSSSignatureState) + |
| 173 |
/*r*/ n + |
| 174 |
/*pOTSSign*/ len * n + |
| 175 |
/*pAuthPath*/ h * n; |
| 176 |
return status; |
| 177 |
} |
| 178 |
|
| 179 |
/*F* |
| 180 |
// Name: ippsXMSSPublicKeyStateGetSize |
| 181 |
// |
| 182 |
// Purpose: Get the XMSS public key state size (bytes). |
| 183 |
// |
| 184 |
// Returns: Reason: |
| 185 |
// ippStsNullPtrErr pSize == NULL |
| 186 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 187 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 188 |
// ippStsNoErr no errors |
| 189 |
// |
| 190 |
// Parameters: |
| 191 |
// pSize pointer to the size |
| 192 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 193 |
// |
| 194 |
*F*/ |
| 195 |
|
| 196 |
IPPFUN(IppStatus, ippsXMSSPublicKeyStateGetSize, (Ipp32s * pSize, IppsXMSSAlgo OIDAlgo)) |
| 197 |
{ |
| 198 |
IPP_BAD_PTR1_RET(pSize); |
| 199 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 200 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 201 |
IppStatus status = ippStsNoErr; |
| 202 |
cpWOTSParams params; |
| 203 |
Ipp32s h = 0; |
| 204 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 205 |
Ipp32s n = params.n; |
| 206 |
|
| 207 |
*pSize = (Ipp32s)sizeof(IppsXMSSPublicKeyState) + |
| 208 |
/*pRoot*/ n + |
| 209 |
/*pSeed*/ n; |
| 210 |
return status; |
| 211 |
} |
| 212 |
|
| 213 |
/*F* |
| 214 |
// Name: ippsXMSSPrivateKeyStateGetSize |
| 215 |
// |
| 216 |
// Purpose: Get the XMSS private key state size (bytes). |
| 217 |
// |
| 218 |
// Returns: Reason: |
| 219 |
// ippStsNullPtrErr pSize == NULL |
| 220 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 221 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 222 |
// ippStsNoErr no errors |
| 223 |
// |
| 224 |
// Parameters: |
| 225 |
// pSize pointer to the size |
| 226 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 227 |
// |
| 228 |
*F*/ |
| 229 |
|
| 230 |
IPPFUN(IppStatus, ippsXMSSPrivateKeyStateGetSize, (Ipp32s * pSize, IppsXMSSAlgo OIDAlgo)) |
| 231 |
{ |
| 232 |
IPP_BAD_PTR1_RET(pSize); |
| 233 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 234 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 235 |
IppStatus status = ippStsNoErr; |
| 236 |
cpWOTSParams params; |
| 237 |
Ipp32s h = 0; |
| 238 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 239 |
Ipp32s n = params.n; |
| 240 |
|
| 241 |
*pSize = (Ipp32s)sizeof(IppsXMSSPrivateKeyState) + |
| 242 |
/*pSecretSeed*/ n + |
| 243 |
/*pSK_PRF*/ n + |
| 244 |
/*pRoot*/ n + |
| 245 |
/*pPublicSeed*/ n; |
| 246 |
return status; |
| 247 |
} |
| 248 |
|
| 249 |
/*F* |
| 250 |
// Name: ippsXMSSBufferGetSize |
| 251 |
// |
| 252 |
// Purpose: Get the XMSS temporary buffer size (bytes) for signature verification. |
| 253 |
// |
| 254 |
// Returns: Reason: |
| 255 |
// ippStsNullPtrErr pSize == NULL |
| 256 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 257 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 258 |
// ippStsLengthErr maxMessageLength < 1 |
| 259 |
// ippStsLengthErr maxMessageLength > IPP_MAX_32S - (numTempBufs + len) * n |
| 260 |
// ippStsNoErr no errors |
| 261 |
// |
| 262 |
// Parameters: |
| 263 |
// pSize pointer to the size |
| 264 |
// maxMessageLength maximum length of the message |
| 265 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 266 |
// |
| 267 |
*F*/ |
| 268 |
|
| 269 |
/* clang-format off */ |
| 270 |
IPPFUN(IppStatus, ippsXMSSBufferGetSize, (Ipp32s* pSize, |
| 271 |
Ipp32s maxMessageLength, |
| 272 |
IppsXMSSAlgo OIDAlgo)) |
| 273 |
/* clang-format on */ |
| 274 |
{ |
| 275 |
IppStatus status = ippStsNoErr; |
| 276 |
|
| 277 |
IPP_BAD_PTR1_RET(pSize); |
| 278 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 279 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 280 |
IPP_BADARG_RET(maxMessageLength < 1, ippStsLengthErr); |
| 281 |
|
| 282 |
/* Set XMSS parameters */ |
| 283 |
Ipp32s h = 0; |
| 284 |
cpWOTSParams params; |
| 285 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 286 |
IPP_BADARG_RET((ippStsNoErr != status), status) |
| 287 |
|
| 288 |
const Ipp32s numTempBufs = 10; |
| 289 |
|
| 290 |
Ipp32s n = params.n; |
| 291 |
Ipp32s len = params.len; |
| 292 |
// this restriction is needed to avoid overflow of Ipp32s |
| 293 |
IPP_BADARG_RET(maxMessageLength > (Ipp32s)(IPP_MAX_32S) - (numTempBufs + len) * n, |
| 294 |
ippStsLengthErr); |
| 295 |
|
| 296 |
*pSize = (numTempBufs + len) * n + maxMessageLength; |
| 297 |
return status; |
| 298 |
} |
| 299 |
|
| 300 |
/*F* |
| 301 |
// Name: ippsXMSSVerifyBufferGetSize |
| 302 |
// |
| 303 |
// Purpose: Get the XMSS temporary buffer size (bytes) for signature verification. |
| 304 |
// |
| 305 |
// Returns: Reason: |
| 306 |
// ippStsNullPtrErr pSize == NULL |
| 307 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 308 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 309 |
// ippStsLengthErr maxMessageLength < 1 |
| 310 |
// ippStsLengthErr maxMessageLength > IPP_MAX_32S - (numTempBufs + len) * n |
| 311 |
// ippStsNoErr no errors |
| 312 |
// |
| 313 |
// Parameters: |
| 314 |
// pSize pointer to the size |
| 315 |
// maxMessageLength maximum length of the message |
| 316 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 317 |
// |
| 318 |
*F*/ |
| 319 |
|
| 320 |
/* clang-format off */ |
| 321 |
IPPFUN(IppStatus, ippsXMSSVerifyBufferGetSize, (Ipp32s* pSize, |
| 322 |
Ipp32s maxMessageLength, |
| 323 |
IppsXMSSAlgo OIDAlgo)) |
| 324 |
/* clang-format on */ |
| 325 |
{ |
| 326 |
return ippsXMSSBufferGetSize(pSize, maxMessageLength, OIDAlgo); |
| 327 |
} |
| 328 |
|
| 329 |
/*F* |
| 330 |
// Name: ippsXMSSKeyGenBufferGetSize |
| 331 |
// |
| 332 |
// Purpose: Get the XMSS temporary buffer size (bytes) for public and private keys generation. |
| 333 |
// |
| 334 |
// Returns: Reason: |
| 335 |
// ippStsNullPtrErr pSize == NULL |
| 336 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 337 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 338 |
// ippStsNoErr no errors |
| 339 |
// |
| 340 |
// Parameters: |
| 341 |
// pSize pointer to the size |
| 342 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 343 |
// |
| 344 |
*F*/ |
| 345 |
|
| 346 |
IPPFUN(IppStatus, ippsXMSSKeyGenBufferGetSize, (Ipp32s * pSize, IppsXMSSAlgo OIDAlgo)) |
| 347 |
{ |
| 348 |
IppStatus status = ippStsNoErr; |
| 349 |
|
| 350 |
IPP_BAD_PTR1_RET(pSize); |
| 351 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 352 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 353 |
|
| 354 |
/* Set XMSS parameters */ |
| 355 |
Ipp32s h = 0; |
| 356 |
cpWOTSParams params; |
| 357 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 358 |
IPP_BADARG_RET((ippStsNoErr != status), status) |
| 359 |
|
| 360 |
Ipp32s n = params.n; |
| 361 |
Ipp32s len = params.len; |
| 362 |
|
| 363 |
*pSize = (h + 1) * (n + 1) + 2 * len * n + 7 * n + ADRS_SIZE; |
| 364 |
return status; |
| 365 |
} |
| 366 |
|
| 367 |
/*F* |
| 368 |
// Name: ippsXMSSSignBufferGetSize |
| 369 |
// |
| 370 |
// Purpose: Get the XMSS temporary buffer size (bytes) for signature creation. |
| 371 |
// |
| 372 |
// Returns: Reason: |
| 373 |
// ippStsNullPtrErr pSize == NULL |
| 374 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 375 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 376 |
// ippStsLengthErr maxMessageLength < 1 |
| 377 |
// ippStsLengthErr maxMessageLength > IPP_MAX_32S - (n + 5 * n + len + key_gen_size) |
| 378 |
// ippStsNoErr no errors |
| 379 |
// |
| 380 |
// Parameters: |
| 381 |
// pSize pointer to the size |
| 382 |
// maxMessageLength maximum length of the message |
| 383 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 384 |
// |
| 385 |
*F*/ |
| 386 |
|
| 387 |
/* clang-format off */ |
| 388 |
IPPFUN(IppStatus, ippsXMSSSignBufferGetSize, (Ipp32s* pSize, |
| 389 |
Ipp32s maxMessageLength, |
| 390 |
IppsXMSSAlgo OIDAlgo)) |
| 391 |
/* clang-format on */ |
| 392 |
{ |
| 393 |
IppStatus status = ippStsNoErr; |
| 394 |
|
| 395 |
IPP_BAD_PTR1_RET(pSize); |
| 396 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 397 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 398 |
IPP_BADARG_RET(maxMessageLength < 1, ippStsLengthErr); |
| 399 |
|
| 400 |
/* Set XMSS parameters */ |
| 401 |
Ipp32s h = 0; |
| 402 |
cpWOTSParams params; |
| 403 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 404 |
IPP_BADARG_RET((ippStsNoErr != status), status) |
| 405 |
|
| 406 |
Ipp32s n = params.n; |
| 407 |
Ipp32s len = params.len; |
| 408 |
|
| 409 |
Ipp32s key_gen_size; |
| 410 |
status = ippsXMSSKeyGenBufferGetSize(&key_gen_size, OIDAlgo); |
| 411 |
IPP_BADARG_RET((ippStsNoErr != status), status) |
| 412 |
|
| 413 |
// this restriction is needed to avoid overflow of Ipp32s |
| 414 |
IPP_BADARG_RET(maxMessageLength > (Ipp32s)(IPP_MAX_32S) - (n + 5 * n + len + key_gen_size), |
| 415 |
ippStsLengthErr); |
| 416 |
|
| 417 |
*pSize = maxMessageLength + n + 5 * n + len + key_gen_size; |
| 418 |
return status; |
| 419 |
} |
| 420 |
|
| 421 |
/*F* |
| 422 |
// Name: ippsXMSSInitKeyPair |
| 423 |
// |
| 424 |
// Purpose: Init XMSS public and private keys states. |
| 425 |
// |
| 426 |
// Returns: Reason: |
| 427 |
// ippStsNullPtrErr pPrvKey == NULL |
| 428 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 429 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 430 |
// ippStsNoErr no errors |
| 431 |
// |
| 432 |
// Parameters: |
| 433 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 434 |
// pPrvKey pointer to the XMSS private key state |
| 435 |
// pPubKey pointer to the XMSS public key state |
| 436 |
// |
| 437 |
*F*/ |
| 438 |
|
| 439 |
/* clang-format off */ |
| 440 |
IPPFUN(IppStatus, ippsXMSSInitKeyPair, (IppsXMSSAlgo OIDAlgo, |
| 441 |
IppsXMSSPrivateKeyState* pPrvKey, |
| 442 |
IppsXMSSPublicKeyState* pPubKey)) |
| 443 |
/* clang-format on */ |
| 444 |
{ |
| 445 |
IPP_BAD_PTR1_RET(pPrvKey); |
| 446 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 447 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 448 |
IppStatus status = ippStsNoErr; |
| 449 |
cpWOTSParams params; |
| 450 |
Ipp32s h = 0; |
| 451 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 452 |
Ipp32s n = params.n; |
| 453 |
|
| 454 |
// init private key state |
| 455 |
pPrvKey->OIDAlgo = OIDAlgo; |
| 456 |
pPrvKey->idx = 0; |
| 457 |
|
| 458 |
Ipp8u* ptr = (Ipp8u*)pPrvKey; |
| 459 |
|
| 460 |
/* allocate internal contexts */ |
| 461 |
ptr += sizeof(IppsXMSSPrivateKeyState); |
| 462 |
|
| 463 |
pPrvKey->pSecretSeed = (Ipp8u*)(IPP_ALIGNED_PTR((ptr), (int)sizeof(Ipp32u))); |
| 464 |
ptr += n; |
| 465 |
|
| 466 |
pPrvKey->pSK_PRF = (Ipp8u*)(IPP_ALIGNED_PTR((ptr), (int)sizeof(Ipp32u))); |
| 467 |
ptr += n; |
| 468 |
|
| 469 |
pPrvKey->pRoot = ptr; |
| 470 |
ptr += n; |
| 471 |
|
| 472 |
pPrvKey->pPublicSeed = (Ipp8u*)(IPP_ALIGNED_PTR((ptr), (int)sizeof(Ipp32u))); |
| 473 |
|
| 474 |
if (pPubKey != NULL) { |
| 475 |
// init public key state |
| 476 |
pPubKey->OIDAlgo = OIDAlgo; |
| 477 |
|
| 478 |
ptr = (Ipp8u*)pPubKey; |
| 479 |
|
| 480 |
/* allocate internal contexts */ |
| 481 |
ptr += sizeof(IppsXMSSPublicKeyState); |
| 482 |
|
| 483 |
pPubKey->pRoot = ptr; |
| 484 |
ptr += n; |
| 485 |
|
| 486 |
pPubKey->pSeed = (Ipp8u*)(IPP_ALIGNED_PTR((ptr), (int)sizeof(Ipp32u))); |
| 487 |
} |
| 488 |
|
| 489 |
return status; |
| 490 |
} |
| 491 |
|
| 492 |
/*F* |
| 493 |
// Name: ippsXMSSInitSignature |
| 494 |
// |
| 495 |
// Purpose: Init the XMSS signature state. |
| 496 |
// |
| 497 |
// Returns: Reason: |
| 498 |
// ippStsNullPtrErr pState == NULL |
| 499 |
// ippStsBadArgErr OIDAlgo > Max value for IppsXMSSAlgo |
| 500 |
// ippStsBadArgErr OIDAlgo <= 0 |
| 501 |
// ippStsNoErr no errors |
| 502 |
// |
| 503 |
// Parameters: |
| 504 |
// OIDAlgo id of XMSS set of parameters (algorithm) |
| 505 |
// pState pointer to the XMSS signature state |
| 506 |
// |
| 507 |
*F*/ |
| 508 |
|
| 509 |
IPPFUN(IppStatus, ippsXMSSInitSignature, (IppsXMSSAlgo OIDAlgo, IppsXMSSSignatureState* pState)) |
| 510 |
{ |
| 511 |
IPP_BAD_PTR1_RET(pState); |
| 512 |
IPP_BADARG_RET(OIDAlgo > XMSS_SHA2_20_512, ippStsBadArgErr); |
| 513 |
IPP_BADARG_RET(OIDAlgo < XMSS_SHA2_10_256, ippStsBadArgErr); |
| 514 |
IppStatus status = ippStsNoErr; |
| 515 |
cpWOTSParams params; |
| 516 |
Ipp32s h = 0; |
| 517 |
status = cp_xmss_set_params(OIDAlgo, &h, ¶ms); |
| 518 |
Ipp32s n = params.n; |
| 519 |
Ipp32s len = params.len; |
| 520 |
|
| 521 |
pState->idx = 0; |
| 522 |
|
| 523 |
Ipp8u* ptr = (Ipp8u*)pState; |
| 524 |
|
| 525 |
/* allocate internal contexts */ |
| 526 |
ptr += sizeof(IppsXMSSSignatureState); |
| 527 |
|
| 528 |
pState->r = ptr; |
| 529 |
ptr += n; |
| 530 |
|
| 531 |
pState->pOTSSign = ptr; |
| 532 |
ptr += len * n; |
| 533 |
|
| 534 |
pState->pAuthPath = ptr; |
| 535 |
|
| 536 |
return status; |
| 537 |
} |