crypto_aesctr.h 1.7 KB

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