Skip to content

Commit 4dbccf7

Browse files
null0linksmuellerDD
authored andcommitted
add support for RSA keyGen according to FIPS 186-4 appendix B.3.6
Add support for RSA key generation algorithm in accordance with appendix B.3.6 of the FIPS 186-4 standard. Signed-off-by: Karol Brzuskiewicz <[email protected]> Signed-off-by: Michelle Wang <[email protected]> Signed-off-by: Stephan Mueller <[email protected]>
1 parent e4f9d02 commit 4dbccf7

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

parser/parser_rsa.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,28 @@ static int rsa_keygen_helper(const struct json_array *processdata,
337337
int (*callback)(struct rsa_keygen_data *vector, flags_t parsed_flags),
338338
struct rsa_keygen_data *vector)
339339
{
340-
341340
int ret = 0;
341+
const char *bitlens_name = "bitlens";
342+
struct json_object *json_nobj;
343+
unsigned int i;
342344

343-
(void)testvector;
345+
if (!json_find_key(testvector, bitlens_name, &json_nobj, json_type_array)) {
346+
if (!json_nobj) {
347+
logger(LOGGER_ERR,
348+
"Parsing of entry %s with expected array failed\n", bitlens_name);
349+
return -EINVAL;
350+
}
351+
vector->bitlen_in = (unsigned int)json_object_array_length(json_nobj);
352+
for (i = 0; i < vector->bitlen_in; i++) {
353+
struct json_object *testvector =
354+
json_object_array_get_idx(json_nobj, i);
344355

356+
CKNULL_LOG(testvector, -EINVAL, "No vector\n");
357+
vector->bitlen[i] = json_object_get_int(testvector);
358+
}
359+
} else {
360+
vector->bitlen_in = 0;
361+
}
345362
CKINT(callback(vector, parsed_flags));
346363

347364
if (parsed_flags & FLAG_OP_RSA_PQ_B36_PRIMES) {
@@ -364,7 +381,7 @@ static int rsa_keygen_helper(const struct json_array *processdata,
364381
bitlenarray = json_object_new_array();
365382
CKNULL(bitlenarray, -ENOMEM);
366383
/* Append the output JSON stream with test results. */
367-
json_object_object_add(testresult, "bitlens", bitlenarray);
384+
json_object_object_add(testresult, bitlens_name, bitlenarray);
368385
json_object_array_add(bitlenarray,
369386
json_object_new_int((int)vector->bitlen[0]));
370387
json_object_array_add(bitlenarray,
@@ -432,8 +449,23 @@ static int rsa_tester(struct json_object *in, struct json_object *out,
432449
};
433450
const struct json_testresult rsa_keygen_testresult = SET_ARRAY(rsa_keygen_testresult_entries, &rsa_keygen_callbacks);
434451

435-
/* search for empty arrays */
436-
const struct json_array rsa_keygen_test = {NULL, 0 , &rsa_keygen_testresult};
452+
const struct json_entry rsa_keygen_test_entries[] = {
453+
{"xP", {.data.buf = &rsa_keygen_vector.xp, PARSER_BIN},
454+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
455+
{"xP1", {.data.buf = &rsa_keygen_vector.xp1, PARSER_BIN},
456+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
457+
{"xP2", {.data.buf = &rsa_keygen_vector.xp2, PARSER_BIN},
458+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
459+
{"xQ", {.data.buf = &rsa_keygen_vector.xq, PARSER_BIN},
460+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
461+
{"xQ1", {.data.buf = &rsa_keygen_vector.xq1, PARSER_BIN},
462+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
463+
{"xQ2", {.data.buf = &rsa_keygen_vector.xq2, PARSER_BIN},
464+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
465+
{"e", {.data.buf = &rsa_keygen_vector.e, PARSER_BIN},
466+
FLAG_OP_ASYM_TYPE_KEYGEN | FLAG_OP_AFT | FLAG_OP_GDT | FLAG_OP_RSA_PQ_B36_PRIMES | FLAG_OPTIONAL },
467+
};
468+
const struct json_array rsa_keygen_test = SET_ARRAY(rsa_keygen_test_entries, &rsa_keygen_testresult);
437469

438470
/**********************************************************************
439471
* RSA B.3.2 KeyGen KAT and KeyGen GDT

parser/parser_rsa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct rsa_keygen_prime_data {
7676
* @var xq [out]
7777
* @var xq1 [out]
7878
* @var xq2 [out]
79+
* @var bitlen_in [in]
7980
* @var bitlen [out]
8081
*
8182
* The following buffers are for CRT key format.
@@ -99,6 +100,7 @@ struct rsa_keygen_data {
99100
struct buffer xq;
100101
struct buffer xq1;
101102
struct buffer xq2;
103+
unsigned int bitlen_in;
102104
unsigned int bitlen[4];
103105

104106
struct buffer dmp1;

0 commit comments

Comments
 (0)