File: s2n_pkey.h

package info (click to toggle)
aws-crt-python 0.28.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,428 kB
  • sloc: ansic: 437,955; python: 27,657; makefile: 5,855; sh: 4,289; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (69 lines) | stat: -rw-r--r-- 3,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#pragma once

#include <openssl/evp.h>

#include "crypto/s2n_hash.h"
#include "crypto/s2n_signature.h"
#include "utils/s2n_blob.h"
#include "utils/s2n_result.h"

/* Public/Private Key Type */
typedef enum {
    S2N_PKEY_TYPE_UNKNOWN = -1,
    S2N_PKEY_TYPE_RSA = 0,
    S2N_PKEY_TYPE_ECDSA,
    S2N_PKEY_TYPE_RSA_PSS,
    S2N_PKEY_TYPE_MLDSA,
    S2N_PKEY_TYPE_SENTINEL
} s2n_pkey_type;

/* Structure that models a public or private key and type-specific operations */
struct s2n_pkey {
    EVP_PKEY *pkey;

    S2N_RESULT (*size)(const struct s2n_pkey *key, uint32_t *size_out);
    int (*sign)(const struct s2n_pkey *priv_key, s2n_signature_algorithm sig_alg,
            struct s2n_hash_state *digest, struct s2n_blob *signature);
    int (*verify)(const struct s2n_pkey *pub_key, s2n_signature_algorithm sig_alg,
            struct s2n_hash_state *digest, struct s2n_blob *signature);
    int (*encrypt)(const struct s2n_pkey *key, struct s2n_blob *in, struct s2n_blob *out);
    int (*decrypt)(const struct s2n_pkey *key, struct s2n_blob *in, struct s2n_blob *out);
};

int s2n_pkey_zero_init(struct s2n_pkey *pkey);
S2N_RESULT s2n_pkey_setup_for_type(struct s2n_pkey *pkey, s2n_pkey_type pkey_type);
int s2n_pkey_check_key_exists(const struct s2n_pkey *pkey);

S2N_RESULT s2n_pkey_size(const struct s2n_pkey *pkey, uint32_t *size_out);
int s2n_pkey_sign(const struct s2n_pkey *pkey, s2n_signature_algorithm sig_alg,
        struct s2n_hash_state *digest, struct s2n_blob *signature);
int s2n_pkey_verify(const struct s2n_pkey *pkey, s2n_signature_algorithm sig_alg,
        struct s2n_hash_state *digest, struct s2n_blob *signature);
int s2n_pkey_encrypt(const struct s2n_pkey *pkey, struct s2n_blob *in, struct s2n_blob *out);
int s2n_pkey_decrypt(const struct s2n_pkey *pkey, struct s2n_blob *in, struct s2n_blob *out);
int s2n_pkey_match(const struct s2n_pkey *pub_key, const struct s2n_pkey *priv_key);
int s2n_pkey_free(struct s2n_pkey *pkey);

S2N_RESULT s2n_pkey_init_hash(const struct s2n_pkey *pkey,
        s2n_signature_algorithm sig_alg, struct s2n_hash_state *hash);

S2N_RESULT s2n_asn1der_to_private_key(struct s2n_pkey *priv_key, struct s2n_blob *asn1der, int type_hint);
S2N_RESULT s2n_asn1der_to_public_key_and_type(struct s2n_pkey *pub_key, s2n_pkey_type *pkey_type, struct s2n_blob *asn1der);
S2N_RESULT s2n_pkey_get_type(EVP_PKEY *evp_pkey, s2n_pkey_type *pkey_type);
S2N_RESULT s2n_pkey_from_x509(X509 *cert, struct s2n_pkey *pub_key_out,
        s2n_pkey_type *pkey_type_out);