Commit 3877869d authored by Herbert Xu's avatar Herbert Xu
Browse files

Merge branch 'ecc'

This pulls in the NIST P384/256/192 x509 changes.
parents befb1dda 2a8e6154
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -242,6 +242,16 @@ config CRYPTO_ECDH
	help
	  Generic implementation of the ECDH algorithm

config CRYPTO_ECDSA
	tristate "ECDSA (NIST P192, P256 etc.) algorithm"
	select CRYPTO_ECC
	select CRYPTO_AKCIPHER
	select ASN1
	help
	  Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.)
	  is A NIST cryptographic standard algorithm. Only signature verification
	  is implemented.

config CRYPTO_ECRDSA
	tristate "EC-RDSA (GOST 34.10) algorithm"
	select CRYPTO_ECC
+6 −0
Original line number Diff line number Diff line
@@ -50,6 +50,12 @@ sm2_generic-y += sm2.o

obj-$(CONFIG_CRYPTO_SM2) += sm2_generic.o

$(obj)/ecdsasignature.asn1.o: $(obj)/ecdsasignature.asn1.c $(obj)/ecdsasignature.asn1.h
$(obj)/ecdsa.o: $(obj)/ecdsasignature.asn1.h
ecdsa_generic-y += ecdsa.o
ecdsa_generic-y += ecdsasignature.asn1.o
obj-$(CONFIG_CRYPTO_ECDSA) += ecdsa_generic.o

crypto_acompress-y := acompress.o
crypto_acompress-y += scompress.o
obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o
+3 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/seq_file.h>
#include <linux/scatterlist.h>
#include <linux/asn1.h>
#include <keys/asymmetric-subtype.h>
#include <crypto/public_key.h>
#include <crypto/akcipher.h>
@@ -85,7 +86,8 @@ int software_key_determine_akcipher(const char *encoding,
		return n >= CRYPTO_MAX_ALG_NAME ? -EINVAL : 0;
	}

	if (strcmp(encoding, "raw") == 0) {
	if (strcmp(encoding, "raw") == 0 ||
	    strcmp(encoding, "x962") == 0) {
		strcpy(alg_name, pkey->pkey_algo);
		return 0;
	}
+47 −2
Original line number Diff line number Diff line
@@ -227,6 +227,26 @@ int x509_note_pkey_algo(void *context, size_t hdrlen,
		ctx->cert->sig->hash_algo = "sha224";
		goto rsa_pkcs1;

	case OID_id_ecdsa_with_sha1:
		ctx->cert->sig->hash_algo = "sha1";
		goto ecdsa;

	case OID_id_ecdsa_with_sha224:
		ctx->cert->sig->hash_algo = "sha224";
		goto ecdsa;

	case OID_id_ecdsa_with_sha256:
		ctx->cert->sig->hash_algo = "sha256";
		goto ecdsa;

	case OID_id_ecdsa_with_sha384:
		ctx->cert->sig->hash_algo = "sha384";
		goto ecdsa;

	case OID_id_ecdsa_with_sha512:
		ctx->cert->sig->hash_algo = "sha512";
		goto ecdsa;

	case OID_gost2012Signature256:
		ctx->cert->sig->hash_algo = "streebog256";
		goto ecrdsa;
@@ -255,6 +275,11 @@ int x509_note_pkey_algo(void *context, size_t hdrlen,
	ctx->cert->sig->encoding = "raw";
	ctx->algo_oid = ctx->last_oid;
	return 0;
ecdsa:
	ctx->cert->sig->pkey_algo = "ecdsa";
	ctx->cert->sig->encoding = "x962";
	ctx->algo_oid = ctx->last_oid;
	return 0;
}

/*
@@ -276,7 +301,8 @@ int x509_note_signature(void *context, size_t hdrlen,

	if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 ||
	    strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 ||
	    strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0) {
	    strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0 ||
	    strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) {
		/* Discard the BIT STRING metadata */
		if (vlen < 1 || *(const u8 *)value != 0)
			return -EBADMSG;
@@ -459,6 +485,7 @@ int x509_extract_key_data(void *context, size_t hdrlen,
			  const void *value, size_t vlen)
{
	struct x509_parse_context *ctx = context;
	enum OID oid;

	ctx->key_algo = ctx->last_oid;
	switch (ctx->last_oid) {
@@ -470,8 +497,26 @@ int x509_extract_key_data(void *context, size_t hdrlen,
		ctx->cert->pub->pkey_algo = "ecrdsa";
		break;
	case OID_id_ecPublicKey:
		if (parse_OID(ctx->params, ctx->params_size, &oid) != 0)
			return -EBADMSG;

		switch (oid) {
		case OID_sm2:
			ctx->cert->pub->pkey_algo = "sm2";
			break;
		case OID_id_prime192v1:
			ctx->cert->pub->pkey_algo = "ecdsa-nist-p192";
			break;
		case OID_id_prime256v1:
			ctx->cert->pub->pkey_algo = "ecdsa-nist-p256";
			break;
		case OID_id_ansip384r1:
			ctx->cert->pub->pkey_algo = "ecdsa-nist-p384";
			break;
		default:
			return -ENOPKG;
		}
		break;
	default:
		return -ENOPKG;
	}
+3 −1
Original line number Diff line number Diff line
@@ -129,7 +129,9 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
	}

	ret = -EKEYREJECTED;
	if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0)
	if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0 &&
	    (strncmp(cert->pub->pkey_algo, "ecdsa-", 6) != 0 ||
	     strcmp(cert->sig->pkey_algo, "ecdsa") != 0))
		goto out;

	ret = public_key_verify_signature(cert->pub, cert->sig);
Loading