| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include "crypto/s2n_signature.h" |
| 19 |
#include "utils/s2n_blob.h" |
| 20 |
#include "utils/s2n_result.h" |
| 21 |
|
| 22 |
struct s2n_connection; |
| 23 |
|
| 24 |
typedef int (*s2n_async_pkey_sign_complete)(struct s2n_connection *conn, struct s2n_blob *signature); |
| 25 |
typedef int (*s2n_async_pkey_decrypt_complete)(struct s2n_connection *conn, bool rsa_failed, struct s2n_blob *decrypted); |
| 26 |
|
| 27 |
struct s2n_async_pkey_op; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#define S2N_ASYNC_PKEY_GUARD(conn) \ |
| 35 |
do { \ |
| 36 |
__typeof(conn) __tmp_conn = (conn); \ |
| 37 |
POSIX_GUARD_PTR(__tmp_conn); \ |
| 38 |
switch (conn->handshake.async_state) { \ |
| 39 |
case S2N_ASYNC_NOT_INVOKED: \ |
| 40 |
break; \ |
| 41 |
\ |
| 42 |
case S2N_ASYNC_INVOKED: \ |
| 43 |
POSIX_BAIL(S2N_ERR_ASYNC_BLOCKED); \ |
| 44 |
\ |
| 45 |
case S2N_ASYNC_COMPLETE: \ |
| 46 |
\ |
| 47 |
__tmp_conn->handshake.async_state = S2N_ASYNC_NOT_INVOKED; \ |
| 48 |
return S2N_SUCCESS; \ |
| 49 |
} \ |
| 50 |
} while (0) |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#define S2N_ASYNC_PKEY_DECRYPT(conn, encrypted, init_decrypted, on_complete) \ |
| 59 |
return s2n_result_is_ok(s2n_async_pkey_decrypt(conn, encrypted, init_decrypted, on_complete)) ? S2N_SUCCESS : S2N_FAILURE; |
| 60 |
|
| 61 |
#define S2N_ASYNC_PKEY_SIGN(conn, sig_alg, digest, on_complete) \ |
| 62 |
return s2n_result_is_ok(s2n_async_pkey_sign(conn, sig_alg, digest, on_complete)) ? S2N_SUCCESS : S2N_FAILURE; |
| 63 |
|
| 64 |
int s2n_async_pkey_op_perform(struct s2n_async_pkey_op *op, s2n_cert_private_key *key); |
| 65 |
int s2n_async_pkey_op_apply(struct s2n_async_pkey_op *op, struct s2n_connection *conn); |
| 66 |
int s2n_async_pkey_op_free(struct s2n_async_pkey_op *op); |
| 67 |
|
| 68 |
int s2n_async_pkey_op_get_op_type(struct s2n_async_pkey_op *op, s2n_async_pkey_op_type *type); |
| 69 |
int s2n_async_pkey_op_get_input_size(struct s2n_async_pkey_op *op, uint32_t *data_len); |
| 70 |
int s2n_async_pkey_op_get_input(struct s2n_async_pkey_op *op, uint8_t *data, uint32_t data_len); |
| 71 |
int s2n_async_pkey_op_set_output(struct s2n_async_pkey_op *op, const uint8_t *data, uint32_t data_len); |
| 72 |
int s2n_async_pkey_op_set_validation_mode(struct s2n_async_pkey_op *op, s2n_async_pkey_validation_mode mode); |
| 73 |
|
| 74 |
S2N_RESULT s2n_async_pkey_verify_signature(struct s2n_connection *conn, s2n_signature_algorithm sig_alg, |
| 75 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |
| 76 |
S2N_RESULT s2n_async_pkey_decrypt(struct s2n_connection *conn, struct s2n_blob *encrypted, struct s2n_blob *init_decrypted, |
| 77 |
s2n_async_pkey_decrypt_complete on_complete); |
| 78 |
S2N_RESULT s2n_async_pkey_sign(struct s2n_connection *conn, s2n_signature_algorithm sig_alg, struct s2n_hash_state *digest, |
| 79 |
s2n_async_pkey_sign_complete on_complete); |
| 80 |
|
| 81 |
struct s2n_async_pkey_verify_data { |
| 82 |
struct s2n_hash_state digest; |
| 83 |
s2n_signature_algorithm sig_alg; |
| 84 |
struct s2n_blob signature; |
| 85 |
}; |
| 86 |
|
| 87 |
int s2n_async_pkey_verify(struct s2n_connection *conn, s2n_signature_algorithm sig_alg, |
| 88 |
struct s2n_hash_state *digest, struct s2n_blob *signature); |