Debian Codegraph @

crt/s2n/crypto/s2n_pkey.h

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
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 /* Public/Private Key Type */
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 /* Structure that models a public or private key and type-specific operations */
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);