prp.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * cifra - embedded cryptography library
  3. * Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
  4. *
  5. * To the extent possible under law, the author(s) have dedicated all
  6. * copyright and related and neighboring rights to this software to the
  7. * public domain worldwide. This software is distributed without any
  8. * warranty.
  9. *
  10. * You should have received a copy of the CC0 Public Domain Dedication
  11. * along with this software. If not, see
  12. * <http://creativecommons.org/publicdomain/zero/1.0/>.
  13. */
  14. #ifndef PRP_H
  15. #define PRP_H
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. /**
  19. * General block cipher description
  20. * ================================
  21. * This allows us to implement block cipher modes which can work
  22. * with different block ciphers.
  23. */
  24. /* .. c:type:: cf_prp_block
  25. * Block processing function type.
  26. *
  27. * The `in` and `out` blocks may alias.
  28. *
  29. * :rtype: void
  30. * :param ctx: block cipher-specific context object.
  31. * :param in: input block.
  32. * :param out: output block.
  33. */
  34. typedef void (*cf_prp_block)(void *ctx, const uint8_t *in, uint8_t *out);
  35. /* .. c:type:: cf_prp
  36. * Describes an PRP in a general way.
  37. *
  38. * .. c:member:: cf_prp.blocksz
  39. * Block size in bytes. Must be no more than :c:macro:`CF_MAXBLOCK`.
  40. *
  41. * .. c:member:: cf_prp.encrypt
  42. * Block encryption function.
  43. *
  44. * .. c:member:: cf_prp.decrypt
  45. * Block decryption function.
  46. */
  47. typedef struct
  48. {
  49. size_t blocksz;
  50. cf_prp_block encrypt;
  51. cf_prp_block decrypt;
  52. } cf_prp;
  53. /* .. c:macro:: CF_MAXBLOCK
  54. * The maximum block cipher blocksize we support, in bytes.
  55. */
  56. #define CF_MAXBLOCK 16
  57. #endif