1/*-
2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_crypto.c 173746 2007-11-19 08:59:32Z jb $");
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/uio.h>
36#else
--- 27 unchanged lines hidden (view full) ---
64 struct cryptop *crp;
65 struct cryptodesc *crd;
66 struct uio *uio;
67 struct iovec *iov;
68 uint64_t sid;
69 u_char *p;
70 int error;
71
72 bzero(&cri, sizeof(cri));
73 cri.cri_alg = algo;
74 cri.cri_key = __DECONST(void *, key);
75 cri.cri_klen = keysize;
76 error = crypto_newsession(&sid, &cri, CRYPTOCAP_F_SOFTWARE);
77 if (error != 0)
78 return (error);
79 p = malloc(sizeof(*crp) + sizeof(*crd) + sizeof(*uio) + sizeof(*iov),
--- 51 unchanged lines hidden (view full) ---
131g_eli_crypto_cipher(u_int algo, int enc, u_char *data, size_t datasize,
132 const u_char *key, size_t keysize)
133{
134 EVP_CIPHER_CTX ctx;
135 const EVP_CIPHER *type;
136 u_char iv[keysize];
137 int outsize;
138
139 switch (algo) {
140 case CRYPTO_NULL_CBC:
141 type = EVP_enc_null();
142 break;
143 case CRYPTO_AES_CBC:
144 switch (keysize) {
145 case 128:
146 type = EVP_aes_128_cbc();
--- 60 unchanged lines hidden (view full) ---
207}
208#endif /* !_KERNEL */
209
210int
211g_eli_crypto_encrypt(u_int algo, u_char *data, size_t datasize,
212 const u_char *key, size_t keysize)
213{
214
215 return (g_eli_crypto_cipher(algo, 1, data, datasize, key, keysize));
216}
217
218int
219g_eli_crypto_decrypt(u_int algo, u_char *data, size_t datasize,
220 const u_char *key, size_t keysize)
221{
222
223 return (g_eli_crypto_cipher(algo, 0, data, datasize, key, keysize));
224}
225
226void
227g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
228 size_t hkeylen)
229{
230 u_char k_ipad[128], key[128];
--- 63 unchanged lines hidden ---
2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_crypto.c 173746 2007-11-19 08:59:32Z jb $");
29
30#include <sys/param.h>
31#ifdef _KERNEL
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/uio.h>
36#else
--- 27 unchanged lines hidden (view full) ---
64 struct cryptop *crp;
65 struct cryptodesc *crd;
66 struct uio *uio;
67 struct iovec *iov;
68 uint64_t sid;
69 u_char *p;
70 int error;
71
72 bzero(&cri, sizeof(cri));
73 cri.cri_alg = algo;
74 cri.cri_key = __DECONST(void *, key);
75 cri.cri_klen = keysize;
76 error = crypto_newsession(&sid, &cri, CRYPTOCAP_F_SOFTWARE);
77 if (error != 0)
78 return (error);
79 p = malloc(sizeof(*crp) + sizeof(*crd) + sizeof(*uio) + sizeof(*iov),
--- 51 unchanged lines hidden (view full) ---
131g_eli_crypto_cipher(u_int algo, int enc, u_char *data, size_t datasize,
132 const u_char *key, size_t keysize)
133{
134 EVP_CIPHER_CTX ctx;
135 const EVP_CIPHER *type;
136 u_char iv[keysize];
137 int outsize;
138
139 switch (algo) {
140 case CRYPTO_NULL_CBC:
141 type = EVP_enc_null();
142 break;
143 case CRYPTO_AES_CBC:
144 switch (keysize) {
145 case 128:
146 type = EVP_aes_128_cbc();
--- 60 unchanged lines hidden (view full) ---
207}
208#endif /* !_KERNEL */
209
210int
211g_eli_crypto_encrypt(u_int algo, u_char *data, size_t datasize,
212 const u_char *key, size_t keysize)
213{
214
215 return (g_eli_crypto_cipher(algo, 1, data, datasize, key, keysize));
216}
217
218int
219g_eli_crypto_decrypt(u_int algo, u_char *data, size_t datasize,
220 const u_char *key, size_t keysize)
221{
222
223 return (g_eli_crypto_cipher(algo, 0, data, datasize, key, keysize));
224}
225
226void
227g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey,
228 size_t hkeylen)
229{
230 u_char k_ipad[128], key[128];
--- 63 unchanged lines hidden ---