Skip to content

Commit 4e66029

Browse files
stefanbergerherbertx
authored andcommitted
crypto: ecdsa - Add support for ECDSA signature verification
Add support for parsing the parameters of a NIST P256 or NIST P192 key. Enable signature verification using these keys. The new module is enabled with CONFIG_ECDSA: Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.) is A NIST cryptographic standard algorithm. Only signature verification is implemented. Cc: Herbert Xu <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: [email protected] Signed-off-by: Stefan Berger <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 7547738 commit 4e66029

File tree

8 files changed

+671
-11
lines changed

8 files changed

+671
-11
lines changed

crypto/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ config CRYPTO_ECDH
242242
help
243243
Generic implementation of the ECDH algorithm
244244

245+
config CRYPTO_ECDSA
246+
tristate "ECDSA (NIST P192, P256 etc.) algorithm"
247+
select CRYPTO_ECC
248+
select CRYPTO_AKCIPHER
249+
select ASN1
250+
help
251+
Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.)
252+
is A NIST cryptographic standard algorithm. Only signature verification
253+
is implemented.
254+
245255
config CRYPTO_ECRDSA
246256
tristate "EC-RDSA (GOST 34.10) algorithm"
247257
select CRYPTO_ECC

crypto/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ sm2_generic-y += sm2.o
5050

5151
obj-$(CONFIG_CRYPTO_SM2) += sm2_generic.o
5252

53+
$(obj)/ecdsasignature.asn1.o: $(obj)/ecdsasignature.asn1.c $(obj)/ecdsasignature.asn1.h
54+
$(obj)/ecdsa.o: $(obj)/ecdsasignature.asn1.h
55+
ecdsa_generic-y += ecdsa.o
56+
ecdsa_generic-y += ecdsasignature.asn1.o
57+
obj-$(CONFIG_CRYPTO_ECDSA) += ecdsa_generic.o
58+
5359
crypto_acompress-y := acompress.o
5460
crypto_acompress-y += scompress.o
5561
obj-$(CONFIG_CRYPTO_ACOMP2) += crypto_acompress.o

crypto/ecc.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct {
4242
u64 m_high;
4343
} uint128_t;
4444

45-
static inline const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
45+
const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
4646
{
4747
switch (curve_id) {
4848
/* In FIPS mode only allow P256 and higher */
@@ -54,6 +54,7 @@ static inline const struct ecc_curve *ecc_get_curve(unsigned int curve_id)
5454
return NULL;
5555
}
5656
}
57+
EXPORT_SYMBOL(ecc_get_curve);
5758

5859
static u64 *ecc_alloc_digits_space(unsigned int ndigits)
5960
{
@@ -1281,16 +1282,6 @@ void ecc_point_mult_shamir(const struct ecc_point *result,
12811282
}
12821283
EXPORT_SYMBOL(ecc_point_mult_shamir);
12831284

1284-
static inline void ecc_swap_digits(const u64 *in, u64 *out,
1285-
unsigned int ndigits)
1286-
{
1287-
const __be64 *src = (__force __be64 *)in;
1288-
int i;
1289-
1290-
for (i = 0; i < ndigits; i++)
1291-
out[i] = be64_to_cpu(src[ndigits - 1 - i]);
1292-
}
1293-
12941285
static int __ecc_is_key_valid(const struct ecc_curve *curve,
12951286
const u64 *private_key, unsigned int ndigits)
12961287
{

crypto/ecc.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
#define ECC_DIGITS_TO_BYTES_SHIFT 3
3535

36+
#define ECC_MAX_BYTES (ECC_MAX_DIGITS << ECC_DIGITS_TO_BYTES_SHIFT)
37+
3638
/**
3739
* struct ecc_point - elliptic curve point in affine coordinates
3840
*
@@ -70,6 +72,29 @@ struct ecc_curve {
7072
u64 *b;
7173
};
7274

75+
/**
76+
* ecc_swap_digits() - Copy ndigits from big endian array to native array
77+
* @in: Input array
78+
* @out: Output array
79+
* @ndigits: Number of digits to copy
80+
*/
81+
static inline void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits)
82+
{
83+
const __be64 *src = (__force __be64 *)in;
84+
int i;
85+
86+
for (i = 0; i < ndigits; i++)
87+
out[i] = be64_to_cpu(src[ndigits - 1 - i]);
88+
}
89+
90+
/**
91+
* ecc_get_curve() - Get a curve given its curve_id
92+
* @curve_id: Id of the curve
93+
*
94+
* Returns pointer to the curve data, NULL if curve is not available
95+
*/
96+
const struct ecc_curve *ecc_get_curve(unsigned int curve_id);
97+
7398
/**
7499
* ecc_is_key_valid() - Validate a given ECDH private key
75100
*

0 commit comments

Comments
 (0)