| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <openssl/evp.h> |
| 19 |
|
| 20 |
#include "crypto/s2n_hash.h" |
| 21 |
#include "crypto/s2n_signature.h" |
| 22 |
#include "utils/s2n_blob.h" |
| 23 |
#include "utils/s2n_result.h" |
| 24 |
|
| 25 |
|
| 26 |
typedef enum { |
| 27 |
S2N_PKEY_TYPE_UNKNOWN = -1, |
| 28 |
S2N_PKEY_TYPE_RSA = 0, |
| 29 |
S2N_PKEY_TYPE_ECDSA, |
| 30 |
S2N_PKEY_TYPE_RSA_PSS, |
| 31 |
S2N_PKEY_TYPE_MLDSA, |
| 32 |
S2N_PKEY_TYPE_SENTINEL |
| 33 |
} s2n_pkey_type; |
| 34 |
|
| 35 |
|
| 36 |
struct s2n_pkey { |
| 37 |
EVP_PKEY *pkey; |
| 38 |
|
| 39 |
S2N_RESULT (*size)(const struct s2n_pkey *key, uint32_t *size_out); |
| 40 |
int (*sign)(const struct s2n_pkey *priv_key, s2n_signature_algorithm sig_alg, |
| 41 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |
| 42 |
int (*verify)(const struct s2n_pkey *pub_key, s2n_signature_algorithm sig_alg, |
| 43 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |
| 44 |
int (*encrypt)(const struct s2n_pkey *key, struct s2n_blob *in, struct s2n_blob *out); |
| 45 |
int (*decrypt)(const struct s2n_pkey *key, struct s2n_blob *in, struct s2n_blob *out); |
| 46 |
}; |
| 47 |
|
| 48 |
int s2n_pkey_zero_init(struct s2n_pkey *pkey); |
| 49 |
S2N_RESULT s2n_pkey_setup_for_type(struct s2n_pkey *pkey, s2n_pkey_type pkey_type); |
| 50 |
int s2n_pkey_check_key_exists(const struct s2n_pkey *pkey); |
| 51 |
|
| 52 |
S2N_RESULT s2n_pkey_size(const struct s2n_pkey *pkey, uint32_t *size_out); |
| 53 |
int s2n_pkey_sign(const struct s2n_pkey *pkey, s2n_signature_algorithm sig_alg, |
| 54 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |
| 55 |
int s2n_pkey_verify(const struct s2n_pkey *pkey, s2n_signature_algorithm sig_alg, |
| 56 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |
| 57 |
int s2n_pkey_encrypt(const struct s2n_pkey *pkey, struct s2n_blob *in, struct s2n_blob *out); |
| 58 |
int s2n_pkey_decrypt(const struct s2n_pkey *pkey, struct s2n_blob *in, struct s2n_blob *out); |
| 59 |
int s2n_pkey_match(const struct s2n_pkey *pub_key, const struct s2n_pkey *priv_key); |
| 60 |
int s2n_pkey_free(struct s2n_pkey *pkey); |
| 61 |
|
| 62 |
S2N_RESULT s2n_pkey_init_hash(const struct s2n_pkey *pkey, |
| 63 |
s2n_signature_algorithm sig_alg, struct s2n_hash_state *hash); |
| 64 |
|
| 65 |
S2N_RESULT s2n_asn1der_to_private_key(struct s2n_pkey *priv_key, struct s2n_blob *asn1der, int type_hint); |
| 66 |
S2N_RESULT s2n_asn1der_to_public_key_and_type(struct s2n_pkey *pub_key, s2n_pkey_type *pkey_type, struct s2n_blob *asn1der); |
| 67 |
S2N_RESULT s2n_pkey_get_type(EVP_PKEY *evp_pkey, s2n_pkey_type *pkey_type); |
| 68 |
S2N_RESULT s2n_pkey_from_x509(X509 *cert, struct s2n_pkey *pub_key_out, |
| 69 |
s2n_pkey_type *pkey_type_out); |