diff options
Diffstat (limited to 'include/crypto/akcipher.h')
-rw-r--r-- | include/crypto/akcipher.h | 90 |
1 files changed, 68 insertions, 22 deletions
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h index 69d163e39101..45cd5b328040 100644 --- a/include/crypto/akcipher.h +++ b/include/crypto/akcipher.h | |||
@@ -18,21 +18,21 @@ | |||
18 | * struct akcipher_request - public key request | 18 | * struct akcipher_request - public key request |
19 | * | 19 | * |
20 | * @base: Common attributes for async crypto requests | 20 | * @base: Common attributes for async crypto requests |
21 | * @src: Pointer to memory containing the input parameters | 21 | * @src: Source data |
22 | * The format of the parameter(s) is expeted to be Octet String | 22 | * @dst: Destination data |
23 | * @dst: Pointer to memory whare the result will be stored | 23 | * @src_len: Size of the input buffer |
24 | * @src_len: Size of the input parameter | ||
25 | * @dst_len: Size of the output buffer. It needs to be at leaset | 24 | * @dst_len: Size of the output buffer. It needs to be at leaset |
26 | * as big as the expected result depending on the operation | 25 | * as big as the expected result depending on the operation |
27 | * After operation it will be updated with the acctual size of the | 26 | * After operation it will be updated with the acctual size of the |
28 | * result. In case of error, where the dst_len was insufficient, | 27 | * result. |
28 | * In case of error where the dst sgl size was insufficient, | ||
29 | * it will be updated to the size required for the operation. | 29 | * it will be updated to the size required for the operation. |
30 | * @__ctx: Start of private context data | 30 | * @__ctx: Start of private context data |
31 | */ | 31 | */ |
32 | struct akcipher_request { | 32 | struct akcipher_request { |
33 | struct crypto_async_request base; | 33 | struct crypto_async_request base; |
34 | void *src; | 34 | struct scatterlist *src; |
35 | void *dst; | 35 | struct scatterlist *dst; |
36 | unsigned int src_len; | 36 | unsigned int src_len; |
37 | unsigned int dst_len; | 37 | unsigned int dst_len; |
38 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | 38 | void *__ctx[] CRYPTO_MINALIGN_ATTR; |
@@ -67,8 +67,13 @@ struct crypto_akcipher { | |||
67 | * algorithm. In case of error, where the dst_len was insufficient, | 67 | * algorithm. In case of error, where the dst_len was insufficient, |
68 | * the req->dst_len will be updated to the size required for the | 68 | * the req->dst_len will be updated to the size required for the |
69 | * operation | 69 | * operation |
70 | * @setkey: Function invokes the algorithm specific set key function, which | 70 | * @set_pub_key: Function invokes the algorithm specific set public key |
71 | * knows how to decode and interpret the BER encoded key | 71 | * function, which knows how to decode and interpret |
72 | * the BER encoded public key | ||
73 | * @set_priv_key: Function invokes the algorithm specific set private key | ||
74 | * function, which knows how to decode and interpret | ||
75 | * the BER encoded private key | ||
76 | * @max_size: Function returns dest buffer size reqired for a given key. | ||
72 | * @init: Initialize the cryptographic transformation object. | 77 | * @init: Initialize the cryptographic transformation object. |
73 | * This function is used to initialize the cryptographic | 78 | * This function is used to initialize the cryptographic |
74 | * transformation object. This function is called only once at | 79 | * transformation object. This function is called only once at |
@@ -89,8 +94,11 @@ struct akcipher_alg { | |||
89 | int (*verify)(struct akcipher_request *req); | 94 | int (*verify)(struct akcipher_request *req); |
90 | int (*encrypt)(struct akcipher_request *req); | 95 | int (*encrypt)(struct akcipher_request *req); |
91 | int (*decrypt)(struct akcipher_request *req); | 96 | int (*decrypt)(struct akcipher_request *req); |
92 | int (*setkey)(struct crypto_akcipher *tfm, const void *key, | 97 | int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key, |
93 | unsigned int keylen); | 98 | unsigned int keylen); |
99 | int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key, | ||
100 | unsigned int keylen); | ||
101 | int (*max_size)(struct crypto_akcipher *tfm); | ||
94 | int (*init)(struct crypto_akcipher *tfm); | 102 | int (*init)(struct crypto_akcipher *tfm); |
95 | void (*exit)(struct crypto_akcipher *tfm); | 103 | void (*exit)(struct crypto_akcipher *tfm); |
96 | 104 | ||
@@ -229,14 +237,14 @@ static inline void akcipher_request_set_callback(struct akcipher_request *req, | |||
229 | * Sets parameters required by crypto operation | 237 | * Sets parameters required by crypto operation |
230 | * | 238 | * |
231 | * @req: public key request | 239 | * @req: public key request |
232 | * @src: ptr to input parameter | 240 | * @src: ptr to input scatter list |
233 | * @dst: ptr of output parameter | 241 | * @dst: ptr to output scatter list |
234 | * @src_len: size of the input buffer | 242 | * @src_len: size of the src input scatter list to be processed |
235 | * @dst_len: size of the output buffer. It will be updated by the | 243 | * @dst_len: size of the dst output scatter list |
236 | * implementation to reflect the acctual size of the result | ||
237 | */ | 244 | */ |
238 | static inline void akcipher_request_set_crypt(struct akcipher_request *req, | 245 | static inline void akcipher_request_set_crypt(struct akcipher_request *req, |
239 | void *src, void *dst, | 246 | struct scatterlist *src, |
247 | struct scatterlist *dst, | ||
240 | unsigned int src_len, | 248 | unsigned int src_len, |
241 | unsigned int dst_len) | 249 | unsigned int dst_len) |
242 | { | 250 | { |
@@ -247,6 +255,22 @@ static inline void akcipher_request_set_crypt(struct akcipher_request *req, | |||
247 | } | 255 | } |
248 | 256 | ||
249 | /** | 257 | /** |
258 | * crypto_akcipher_maxsize() -- Get len for output buffer | ||
259 | * | ||
260 | * Function returns the dest buffer size required for a given key | ||
261 | * | ||
262 | * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() | ||
263 | * | ||
264 | * Return: minimum len for output buffer or error code in key hasn't been set | ||
265 | */ | ||
266 | static inline int crypto_akcipher_maxsize(struct crypto_akcipher *tfm) | ||
267 | { | ||
268 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
269 | |||
270 | return alg->max_size(tfm); | ||
271 | } | ||
272 | |||
273 | /** | ||
250 | * crypto_akcipher_encrypt() -- Invoke public key encrypt operation | 274 | * crypto_akcipher_encrypt() -- Invoke public key encrypt operation |
251 | * | 275 | * |
252 | * Function invokes the specific public key encrypt operation for a given | 276 | * Function invokes the specific public key encrypt operation for a given |
@@ -319,22 +343,44 @@ static inline int crypto_akcipher_verify(struct akcipher_request *req) | |||
319 | } | 343 | } |
320 | 344 | ||
321 | /** | 345 | /** |
322 | * crypto_akcipher_setkey() -- Invoke public key setkey operation | 346 | * crypto_akcipher_set_pub_key() -- Invoke set public key operation |
347 | * | ||
348 | * Function invokes the algorithm specific set key function, which knows | ||
349 | * how to decode and interpret the encoded key | ||
350 | * | ||
351 | * @tfm: tfm handle | ||
352 | * @key: BER encoded public key | ||
353 | * @keylen: length of the key | ||
354 | * | ||
355 | * Return: zero on success; error code in case of error | ||
356 | */ | ||
357 | static inline int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm, | ||
358 | const void *key, | ||
359 | unsigned int keylen) | ||
360 | { | ||
361 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
362 | |||
363 | return alg->set_pub_key(tfm, key, keylen); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * crypto_akcipher_set_priv_key() -- Invoke set private key operation | ||
323 | * | 368 | * |
324 | * Function invokes the algorithm specific set key function, which knows | 369 | * Function invokes the algorithm specific set key function, which knows |
325 | * how to decode and interpret the encoded key | 370 | * how to decode and interpret the encoded key |
326 | * | 371 | * |
327 | * @tfm: tfm handle | 372 | * @tfm: tfm handle |
328 | * @key: BER encoded private or public key | 373 | * @key: BER encoded private key |
329 | * @keylen: length of the key | 374 | * @keylen: length of the key |
330 | * | 375 | * |
331 | * Return: zero on success; error code in case of error | 376 | * Return: zero on success; error code in case of error |
332 | */ | 377 | */ |
333 | static inline int crypto_akcipher_setkey(struct crypto_akcipher *tfm, void *key, | 378 | static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm, |
334 | unsigned int keylen) | 379 | const void *key, |
380 | unsigned int keylen) | ||
335 | { | 381 | { |
336 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | 382 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); |
337 | 383 | ||
338 | return alg->setkey(tfm, key, keylen); | 384 | return alg->set_priv_key(tfm, key, keylen); |
339 | } | 385 | } |
340 | #endif | 386 | #endif |