| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "internal.h" |
| 22 |
#include "kcapi.h" |
| 23 |
|
| 24 |
int kcapi_kpp_init(struct kcapi_handle **handle, const char *ciphername, |
| 25 |
uint32_t flags) |
| 26 |
{ |
| 27 |
int ret = _kcapi_handle_init(handle, "kpp", ciphername, flags); |
| 28 |
|
| 29 |
if (ret) |
| 30 |
return ret; |
| 31 |
|
| 32 |
return 0; |
| 33 |
} |
| 34 |
|
| 35 |
void kcapi_kpp_destroy(struct kcapi_handle *handle) |
| 36 |
{ |
| 37 |
_kcapi_handle_destroy(handle); |
| 38 |
} |
| 39 |
|
| 40 |
int kcapi_kpp_dh_setparam_pkcs3(struct kcapi_handle *handle, |
| 41 |
const uint8_t *pkcs3, uint32_t pkcs3len) |
| 42 |
{ |
| 43 |
struct kcapi_handle_tfm *tfm = handle->tfm; |
| 44 |
int ret = 0; |
| 45 |
|
| 46 |
ret = setsockopt(tfm->tfmfd, SOL_ALG, ALG_SET_DH_PARAMETERS, |
| 47 |
pkcs3, pkcs3len); |
| 48 |
return (ret >= 0) ? ret : -errno; |
| 49 |
} |
| 50 |
|
| 51 |
int kcapi_kpp_ecdh_setcurve(struct kcapi_handle *handle, |
| 52 |
unsigned long curve_id) |
| 53 |
{ |
| 54 |
struct kcapi_handle_tfm *tfm = handle->tfm; |
| 55 |
char curve_id_str[sizeof(unsigned long)]; |
| 56 |
int ret = 0; |
| 57 |
|
| 58 |
snprintf(curve_id_str, sizeof(curve_id_str), "%lu", curve_id); |
| 59 |
ret = setsockopt(tfm->tfmfd, SOL_ALG, ALG_SET_ECDH_CURVE, |
| 60 |
curve_id_str, sizeof(curve_id_str)); |
| 61 |
return (ret >= 0) ? ret : -errno; |
| 62 |
} |
| 63 |
|
| 64 |
int kcapi_kpp_setkey(struct kcapi_handle *handle, |
| 65 |
const uint8_t *key, uint32_t keylen) |
| 66 |
{ |
| 67 |
return _kcapi_common_setkey(handle, key, keylen); |
| 68 |
} |
| 69 |
|
| 70 |
IMPL_SYMVER(kpp_keygen, "1.3.1") |
| 71 |
ssize_t impl_kpp_keygen(struct kcapi_handle *handle, |
| 72 |
uint8_t *pubkey, size_t pubkeylen, int access) |
| 73 |
{ |
| 74 |
return _kcapi_cipher_crypt(handle, NULL, 0, pubkey, pubkeylen, access, |
| 75 |
ALG_OP_KEYGEN); |
| 76 |
} |
| 77 |
|
| 78 |
ORIG_SYMVER(kpp_keygen, "1.0.0") |
| 79 |
int32_t orig_kpp_keygen(struct kcapi_handle *handle, |
| 80 |
uint8_t *pubkey, uint32_t pubkeylen, int access) |
| 81 |
{ |
| 82 |
return (int32_t)_kcapi_cipher_crypt(handle, NULL, 0, pubkey, pubkeylen, |
| 83 |
access, ALG_OP_KEYGEN); |
| 84 |
} |
| 85 |
|
| 86 |
IMPL_SYMVER(kpp_ssgen, "1.3.1") |
| 87 |
ssize_t impl_kpp_ssgen(struct kcapi_handle *handle, |
| 88 |
const uint8_t *pubkey, size_t pubkeylen, |
| 89 |
uint8_t *ss, size_t sslen, int access) |
| 90 |
{ |
| 91 |
return _kcapi_cipher_crypt(handle, pubkey, pubkeylen, ss, sslen, access, |
| 92 |
ALG_OP_SSGEN); |
| 93 |
} |
| 94 |
|
| 95 |
ORIG_SYMVER(kpp_ssgen, "1.0.0") |
| 96 |
int32_t orig_kpp_ssgen(struct kcapi_handle *handle, |
| 97 |
const uint8_t *pubkey, uint32_t pubkeylen, |
| 98 |
uint8_t *ss, uint32_t sslen, int access) |
| 99 |
{ |
| 100 |
return (int32_t)_kcapi_cipher_crypt(handle, pubkey, pubkeylen, ss, |
| 101 |
sslen, access, ALG_OP_SSGEN); |
| 102 |
} |
| 103 |
|
| 104 |
static ssize_t |
| 105 |
_kcapi_kpp_crypt_aio(struct kcapi_handle *handle, struct iovec *iniov, |
| 106 |
struct iovec *outiov, size_t iovlen, int access, |
| 107 |
unsigned int enc) |
| 108 |
{ |
| 109 |
struct iovec zeroiov; |
| 110 |
ssize_t processed = 0, ret; |
| 111 |
|
| 112 |
|
| 113 |
while (iovlen) { |
| 114 |
ret = _kcapi_cipher_crypt_aio(handle, iniov ? iniov : &zeroiov, |
| 115 |
outiov, 1, access, enc); |
| 116 |
if (ret < 0) |
| 117 |
return ret; |
| 118 |
|
| 119 |
processed += ret; |
| 120 |
|
| 121 |
if (iniov) |
| 122 |
iniov++; |
| 123 |
outiov++; |
| 124 |
iovlen--; |
| 125 |
} |
| 126 |
return processed; |
| 127 |
} |
| 128 |
|
| 129 |
IMPL_SYMVER(kpp_keygen_aio, "1.3.1") |
| 130 |
ssize_t impl_kpp_keygen_aio(struct kcapi_handle *handle, struct iovec *outiov, |
| 131 |
size_t iovlen, int access) |
| 132 |
{ |
| 133 |
return _kcapi_kpp_crypt_aio(handle, NULL, outiov, iovlen, access, |
| 134 |
ALG_OP_KEYGEN); |
| 135 |
} |
| 136 |
|
| 137 |
ORIG_SYMVER(kpp_keygen_aio, "1.0.0") |
| 138 |
int32_t orig_kpp_keygen_aio(struct kcapi_handle *handle, struct iovec *outiov, |
| 139 |
uint32_t iovlen, int access) |
| 140 |
{ |
| 141 |
return (int32_t)_kcapi_kpp_crypt_aio(handle, NULL, outiov, iovlen, |
| 142 |
access, ALG_OP_KEYGEN); |
| 143 |
} |
| 144 |
|
| 145 |
IMPL_SYMVER(kpp_ssgen_aio, "1.3.1") |
| 146 |
ssize_t impl_kpp_ssgen_aio(struct kcapi_handle *handle, |
| 147 |
struct iovec *iniov, struct iovec *outiov, |
| 148 |
size_t iovlen, int access) |
| 149 |
{ |
| 150 |
return _kcapi_kpp_crypt_aio(handle, iniov, outiov, iovlen, access, |
| 151 |
ALG_OP_SSGEN); |
| 152 |
} |
| 153 |
|
| 154 |
ORIG_SYMVER(kpp_ssgen_aio, "1.0.0") |
| 155 |
int32_t orig_kpp_ssgen_aio(struct kcapi_handle *handle, |
| 156 |
struct iovec *iniov, struct iovec *outiov, |
| 157 |
uint32_t iovlen, int access) |
| 158 |
{ |
| 159 |
return (int32_t)_kcapi_kpp_crypt_aio(handle, iniov, outiov, iovlen, |
| 160 |
access, ALG_OP_SSGEN); |
| 161 |
} |