diff options
author | nagendra modadugu <ngm@google.com> | 2015-12-08 21:07:54 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-01-11 22:03:13 -0800 |
commit | 7a254e9851e37a5473efb8e61059d47b52bcee76 (patch) | |
tree | f37e151d293b26962f79234b6103d5245e4f4d0b /chip/g/dcrypto/dcrypto.h | |
parent | 4368dcfb32942740dd11188de6a8658cdd448a5a (diff) | |
download | chrome-ec-7a254e9851e37a5473efb8e61059d47b52bcee76.tar.gz |
Initial RSA implementation.stabilize-7821.B
Includes support for encrypt / decrypt,
and sign / verify; padding schemes OAEP /
PKCS1; supporting bignum library.
RSA key sizes must be a multiple of 32-bits
(with the top bit set). Keying material,
input and output buffers are required to be
word-aligned.
BRANCH=none
TEST=added encrypt/decrypt sign/verify tests, compatibility with openssl tested
BUG=chrome-os-partner:43025,chrome-os-partner:47524
Change-Id: I6bc324c651e3178bb45bb75ab5935d9bc07efbce
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/316942
Commit-Ready: Marius Schilder <mschilder@chromium.org>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Diffstat (limited to 'chip/g/dcrypto/dcrypto.h')
-rw-r--r-- | chip/g/dcrypto/dcrypto.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/chip/g/dcrypto/dcrypto.h b/chip/g/dcrypto/dcrypto.h index a39350fd13..3d8e78ab96 100644 --- a/chip/g/dcrypto/dcrypto.h +++ b/chip/g/dcrypto/dcrypto.h @@ -31,6 +31,11 @@ struct HASH_CTX; /* Forward declaration. */ typedef struct HASH_CTX SHA1_CTX; typedef struct HASH_CTX SHA256_CTX; +enum hashing_mode { + HASH_SHA1 = 0, + HASH_SHA256 = 1 +}; + #define DCRYPTO_HASH_update(ctx, data, len) \ ((ctx)->vtab->update((ctx), (data), (len))) #define DCRYPTO_HASH_final(ctx) \ @@ -72,4 +77,46 @@ const uint8_t *DCRYPTO_SHA1_hash(const uint8_t *data, uint32_t n, const uint8_t *DCRYPTO_SHA256_hash(const uint8_t *data, uint32_t n, uint8_t *digest); +/* + * RSA. + */ + +/* Largest supported key size, 2048-bits. */ +#define RSA_MAX_BYTES 256 +#define RSA_MAX_WORDS (RSA_MAX_BYTES / sizeof(uint32_t)) + +struct RSA { + uint32_t e; + struct BIGNUM N; + struct BIGNUM d; +}; + +enum padding_mode { + PADDING_MODE_PKCS1 = 0, + PADDING_MODE_OAEP = 1 +}; + +/* Calculate r = m ^ e mod N */ +int DCRYPTO_rsa_encrypt(struct RSA *rsa, uint8_t *out, uint32_t *out_len, + const uint8_t *in, const uint32_t in_len, + enum padding_mode padding, enum hashing_mode hashing, + const char *label); + +/* Calculate r = m ^ d mod N */ +int DCRYPTO_rsa_decrypt(struct RSA *rsa, uint8_t *out, uint32_t *out_len, + const uint8_t *in, const uint32_t in_len, + enum padding_mode padding, enum hashing_mode hashing, + const char *label); + +/* Calculate r = m ^ d mod N */ +int DCRYPTO_rsa_sign(struct RSA *rsa, uint8_t *out, uint32_t *out_len, + const uint8_t *in, const uint32_t in_len, + enum padding_mode padding, enum hashing_mode hashing); + +/* Calculate r = m ^ e mod N */ +int DCRYPTO_rsa_verify(struct RSA *rsa, const uint8_t *digest, + uint32_t digest_len, const uint8_t *sig, + const uint32_t sig_len, enum padding_mode padding, + enum hashing_mode hashing); + #endif /* ! __EC_CHIP_G_DCRYPTO_DCRYPTO_H */ |