whitespace and indenting cleanup
[cryptodev-linux.git] / cryptlib.h
blob729679cd266d1f4593f4577e800e9f58db1a52c4
1 #ifndef CRYPTLIB_H
2 # define CRYPTLIB_H
4 struct cipher_data {
5 int init; /* 0 uninitialized */
6 int blocksize;
7 int aead;
8 int stream;
9 int ivsize;
10 int alignmask;
11 struct {
12 /* block ciphers */
13 struct crypto_ablkcipher *s;
14 struct ablkcipher_request *request;
16 /* AEAD ciphers */
17 struct crypto_aead *as;
18 struct aead_request *arequest;
20 struct cryptodev_result *result;
21 uint8_t iv[EALG_MAX_BLOCK_LEN];
22 } async;
25 int cryptodev_cipher_init(struct cipher_data *out, const char *alg_name,
26 uint8_t *key, size_t keylen, int stream, int aead);
27 void cryptodev_cipher_deinit(struct cipher_data *cdata);
28 ssize_t cryptodev_cipher_decrypt(struct cipher_data *cdata,
29 const struct scatterlist *sg1,
30 struct scatterlist *sg2, size_t len);
31 ssize_t cryptodev_cipher_encrypt(struct cipher_data *cdata,
32 const struct scatterlist *sg1,
33 struct scatterlist *sg2, size_t len);
35 /* AEAD */
36 inline static void cryptodev_cipher_auth(struct cipher_data *cdata,
37 struct scatterlist *sg1, size_t len)
39 if( len )
40 aead_request_set_assoc(cdata->async.arequest, sg1, len);
41 else /* for some reason we _have_ to call that */
42 aead_request_set_assoc(cdata->async.arequest, NULL, 0);
45 inline static void cryptodev_cipher_set_tag_size(struct cipher_data *cdata, int size)
47 if (likely(cdata->aead != 0))
48 crypto_aead_setauthsize(cdata->async.as, size);
51 inline static int cryptodev_cipher_get_tag_size(struct cipher_data *cdata)
53 if (likely(cdata->init && cdata->aead != 0))
54 return crypto_aead_authsize(cdata->async.as);
55 else
56 return 0;
59 inline static void cryptodev_cipher_set_iv(struct cipher_data *cdata,
60 void *iv, size_t iv_size)
62 memcpy(cdata->async.iv, iv, min(iv_size, sizeof(cdata->async.iv)));
65 inline static void cryptodev_cipher_get_iv(struct cipher_data *cdata,
66 void *iv, size_t iv_size)
68 memcpy(iv, cdata->async.iv, min(iv_size, sizeof(cdata->async.iv)));
71 /* Hash */
72 struct hash_data {
73 int init; /* 0 uninitialized */
74 int digestsize;
75 int alignmask;
76 struct {
77 struct crypto_ahash *s;
78 struct cryptodev_result *result;
79 struct ahash_request *request;
80 } async;
83 int cryptodev_hash_final(struct hash_data *hdata, void *output);
84 ssize_t cryptodev_hash_update(struct hash_data *hdata,
85 struct scatterlist *sg, size_t len);
86 int cryptodev_hash_reset(struct hash_data *hdata);
87 void cryptodev_hash_deinit(struct hash_data *hdata);
88 int cryptodev_hash_init(struct hash_data *hdata, const char *alg_name,
89 int hmac_mode, void *mackey, size_t mackeylen);
92 #endif