| 1 |
#ifndef AWS_C_CAL_PRIVATE_RSA_H |
| 2 |
#define AWS_C_CAL_PRIVATE_RSA_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <aws/cal/rsa.h> |
| 9 |
|
| 10 |
#include <aws/common/byte_buf.h> |
| 11 |
#include <aws/common/ref_count.h> |
| 12 |
|
| 13 |
struct aws_rsa_key_pair; |
| 14 |
struct aws_der_decoder; |
| 15 |
|
| 16 |
struct aws_rsa_key_vtable { |
| 17 |
int (*encrypt)( |
| 18 |
const struct aws_rsa_key_pair *key_pair, |
| 19 |
enum aws_rsa_encryption_algorithm algorithm, |
| 20 |
struct aws_byte_cursor plaintext, |
| 21 |
struct aws_byte_buf *out); |
| 22 |
int (*decrypt)( |
| 23 |
const struct aws_rsa_key_pair *key_pair, |
| 24 |
enum aws_rsa_encryption_algorithm algorithm, |
| 25 |
struct aws_byte_cursor ciphertext, |
| 26 |
struct aws_byte_buf *out); |
| 27 |
|
| 28 |
int (*sign)( |
| 29 |
const struct aws_rsa_key_pair *key_pair, |
| 30 |
enum aws_rsa_signature_algorithm algorithm, |
| 31 |
struct aws_byte_cursor digest, |
| 32 |
struct aws_byte_buf *out); |
| 33 |
|
| 34 |
int (*verify)( |
| 35 |
const struct aws_rsa_key_pair *key_pair, |
| 36 |
enum aws_rsa_signature_algorithm algorithm, |
| 37 |
struct aws_byte_cursor digest, |
| 38 |
struct aws_byte_cursor signature); |
| 39 |
}; |
| 40 |
|
| 41 |
struct aws_rsa_key_pair { |
| 42 |
struct aws_allocator *allocator; |
| 43 |
struct aws_rsa_key_vtable *vtable; |
| 44 |
struct aws_ref_count ref_count; |
| 45 |
|
| 46 |
size_t key_size_in_bits; |
| 47 |
struct aws_byte_buf priv; |
| 48 |
struct aws_byte_buf pub; |
| 49 |
|
| 50 |
void *impl; |
| 51 |
}; |
| 52 |
|
| 53 |
void aws_rsa_key_pair_base_clean_up(struct aws_rsa_key_pair *key_pair); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
struct aws_rsa_private_key_pkcs1 { |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
int version; |
| 79 |
struct aws_byte_cursor modulus; |
| 80 |
struct aws_byte_cursor publicExponent; |
| 81 |
struct aws_byte_cursor privateExponent; |
| 82 |
struct aws_byte_cursor prime1; |
| 83 |
struct aws_byte_cursor prime2; |
| 84 |
struct aws_byte_cursor exponent1; |
| 85 |
struct aws_byte_cursor exponent2; |
| 86 |
struct aws_byte_cursor coefficient; |
| 87 |
}; |
| 88 |
|
| 89 |
AWS_CAL_API int aws_der_decoder_load_private_rsa_pkcs1( |
| 90 |
struct aws_der_decoder *decoder, |
| 91 |
struct aws_rsa_private_key_pkcs1 *out); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
struct aws_rsa_public_key_pkcs1 { |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
struct aws_byte_cursor modulus; |
| 105 |
struct aws_byte_cursor publicExponent; |
| 106 |
}; |
| 107 |
|
| 108 |
AWS_CAL_API int aws_der_decoder_load_public_rsa_pkcs1( |
| 109 |
struct aws_der_decoder *decoder, |
| 110 |
struct aws_rsa_public_key_pkcs1 *out); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
int is_valid_rsa_key_size(size_t key_size_in_bits); |
| 117 |
|
| 118 |
#endif |