diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-01 10:32:14 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-01 10:32:14 +0100 |
commit | 4097e27114d227692d53c5d28487e12a3833cd24 (patch) | |
tree | d5c2a62c4db97de94f92150340612c64d3997669 /ccast/axTLS/rsa.c | |
parent | f8a0a4e1c775a90c313cb83201eec4cea4e9a7da (diff) | |
parent | 5514d94483c98e3320b202b1bb882023a7d12027 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'ccast/axTLS/rsa.c')
-rwxr-xr-x[-rw-r--r--] | ccast/axTLS/rsa.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ccast/axTLS/rsa.c b/ccast/axTLS/rsa.c index e707f2b..14948eb 100644..100755 --- a/ccast/axTLS/rsa.c +++ b/ccast/axTLS/rsa.c @@ -188,6 +188,50 @@ int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, } /** + * @brief Use PKCS1.5 for decryption. + * @param ctx [in] The context + * @param in_data [in] The data to encrypt + * @param out_data [out] The decrypted data. + * @return The number of bytes that were originally encrypted. -1 on error. + */ +int RSA_decrypt2(const RSA_CTX *ctx, const uint8_t *in_data, uint8_t *out_data) +{ + const int byte_size = ctx->num_octets; + int i, size; + bigint *decrypted_bi, *dat_bi; + uint8_t *block = (uint8_t *)malloc(byte_size); + + /* decrypt */ + dat_bi = bi_import(ctx->bi_ctx, in_data, byte_size); + + decrypted_bi = RSA_public(ctx, dat_bi); /* Frees dat_bi and exponent ? */ + + /* convert to a normal block (frees decrypted_bi) */ + bi_export(ctx->bi_ctx, decrypted_bi, block, byte_size); + + + /* We assume this is padded with "0001ff....ff00" */ + i = 2; + while (block[i++] == 0xff && i < byte_size) + ; + + /* Skip last 0x00 */ + if (i < byte_size && block[i] == 0x00) + i++; + + size = byte_size - i; + + /* get only the bit we want */ + if (size > 0) { + memcpy(out_data, &block[i], size); + } + + free(block); + + return size ? size : -1; +} + +/** * Performs m = c^d mod n */ bigint *RSA_private(const RSA_CTX *c, bigint *bi_msg) |