Skip to content

Commit fdb4f66

Browse files
xnoxherbertx
authored andcommitted
crypto: asymmetric_keys - allow FIPS 202 SHA-3 signatures
Add FIPS 202 SHA-3 hash signature support in x509 certificates, pkcs7 signatures, and authenticode signatures. Supports hashes of size 256 and up, as 224 is too weak for any practical purposes. Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ee62afb commit fdb4f66

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

crypto/asymmetric_keys/mscode_parser.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ int mscode_note_digest_algo(void *context, size_t hdrlen,
8484
case OID_sha512:
8585
ctx->digest_algo = "sha512";
8686
break;
87+
case OID_sha3_256:
88+
ctx->digest_algo = "sha3-256";
89+
break;
90+
case OID_sha3_384:
91+
ctx->digest_algo = "sha3-384";
92+
break;
93+
case OID_sha3_512:
94+
ctx->digest_algo = "sha3-512";
95+
break;
8796

8897
case OID__NR:
8998
sprint_oid(value, vlen, buffer, sizeof(buffer));

crypto/asymmetric_keys/pkcs7_parser.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ int pkcs7_sig_note_digest_algo(void *context, size_t hdrlen,
248248
case OID_gost2012Digest512:
249249
ctx->sinfo->sig->hash_algo = "streebog512";
250250
break;
251+
case OID_sha3_256:
252+
ctx->sinfo->sig->hash_algo = "sha3-256";
253+
break;
254+
case OID_sha3_384:
255+
ctx->sinfo->sig->hash_algo = "sha3-384";
256+
break;
257+
case OID_sha3_512:
258+
ctx->sinfo->sig->hash_algo = "sha3-512";
259+
break;
251260
default:
252261
printk("Unsupported digest algo: %u\n", ctx->last_oid);
253262
return -ENOPKG;
@@ -273,6 +282,9 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
273282
case OID_id_ecdsa_with_sha256:
274283
case OID_id_ecdsa_with_sha384:
275284
case OID_id_ecdsa_with_sha512:
285+
case OID_id_ecdsa_with_sha3_256:
286+
case OID_id_ecdsa_with_sha3_384:
287+
case OID_id_ecdsa_with_sha3_512:
276288
ctx->sinfo->sig->pkey_algo = "ecdsa";
277289
ctx->sinfo->sig->encoding = "x962";
278290
break;

crypto/asymmetric_keys/public_key.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ software_key_determine_akcipher(const struct public_key *pkey,
119119
if (strcmp(hash_algo, "sha224") != 0 &&
120120
strcmp(hash_algo, "sha256") != 0 &&
121121
strcmp(hash_algo, "sha384") != 0 &&
122-
strcmp(hash_algo, "sha512") != 0)
122+
strcmp(hash_algo, "sha512") != 0 &&
123+
strcmp(hash_algo, "sha3-256") != 0 &&
124+
strcmp(hash_algo, "sha3-384") != 0 &&
125+
strcmp(hash_algo, "sha3-512") != 0)
123126
return -EINVAL;
124127
} else if (strcmp(pkey->pkey_algo, "sm2") == 0) {
125128
if (strcmp(encoding, "raw") != 0)

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag,
214214
ctx->cert->sig->hash_algo = "sha224";
215215
goto rsa_pkcs1;
216216

217+
case OID_id_rsassa_pkcs1_v1_5_with_sha3_256:
218+
ctx->cert->sig->hash_algo = "sha3-256";
219+
goto rsa_pkcs1;
220+
221+
case OID_id_rsassa_pkcs1_v1_5_with_sha3_384:
222+
ctx->cert->sig->hash_algo = "sha3-384";
223+
goto rsa_pkcs1;
224+
225+
case OID_id_rsassa_pkcs1_v1_5_with_sha3_512:
226+
ctx->cert->sig->hash_algo = "sha3-512";
227+
goto rsa_pkcs1;
228+
217229
case OID_id_ecdsa_with_sha224:
218230
ctx->cert->sig->hash_algo = "sha224";
219231
goto ecdsa;
@@ -230,6 +242,18 @@ int x509_note_sig_algo(void *context, size_t hdrlen, unsigned char tag,
230242
ctx->cert->sig->hash_algo = "sha512";
231243
goto ecdsa;
232244

245+
case OID_id_ecdsa_with_sha3_256:
246+
ctx->cert->sig->hash_algo = "sha3-256";
247+
goto ecdsa;
248+
249+
case OID_id_ecdsa_with_sha3_384:
250+
ctx->cert->sig->hash_algo = "sha3-384";
251+
goto ecdsa;
252+
253+
case OID_id_ecdsa_with_sha3_512:
254+
ctx->cert->sig->hash_algo = "sha3-512";
255+
goto ecdsa;
256+
233257
case OID_gost2012Signature256:
234258
ctx->cert->sig->hash_algo = "streebog256";
235259
goto ecrdsa;

0 commit comments

Comments
 (0)