| 1 | #ifndef _CRYPTO_AESCTR_H_ |
| 2 | #define _CRYPTO_AESCTR_H_ |
| 3 | |
| 4 | #include <stddef.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | /* Opaque types. */ |
| 8 | struct crypto_aes_key; |
| 9 | struct crypto_aesctr; |
| 10 | |
| 11 | /** |
| 12 | * crypto_aesctr_init(key, nonce): |
| 13 | * Prepare to encrypt/decrypt data with AES in CTR mode, using the provided |
| 14 | * expanded key and nonce. The key provided must remain valid for the |
| 15 | * lifetime of the stream. |
| 16 | */ |
| 17 | struct crypto_aesctr * crypto_aesctr_init(const struct crypto_aes_key *, |
| 18 | uint64_t); |
| 19 | |
| 20 | /** |
| 21 | * crypto_aesctr_stream(stream, inbuf, outbuf, buflen): |
| 22 | * Generate the next ${buflen} bytes of the AES-CTR stream and xor them with |
| 23 | * bytes from ${inbuf}, writing the result into ${outbuf}. If the buffers |
| 24 | * ${inbuf} and ${outbuf} overlap, they must be identical. |
| 25 | */ |
| 26 | void crypto_aesctr_stream(struct crypto_aesctr *, const uint8_t *, |
| 27 | uint8_t *, size_t); |
| 28 | |
| 29 | /** |
| 30 | * crypto_aesctr_free(stream): |
| 31 | * Free the provided stream object. |
| 32 | */ |
| 33 | void crypto_aesctr_free(struct crypto_aesctr *); |
| 34 | |
| 35 | /** |
| 36 | * crypto_aesctr_buf(key, nonce, inbuf, outbuf, buflen): |
| 37 | * Equivalent to _init(key, nonce); _stream(inbuf, outbuf, buflen); _free(). |
| 38 | */ |
| 39 | void crypto_aesctr_buf(const struct crypto_aes_key *, uint64_t, |
| 40 | const uint8_t *, uint8_t *, size_t); |
| 41 | |
| 42 | #endif /* !_CRYPTO_AESCTR_H_ */ |