xform_enc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* $FreeBSD$ */
  2. /* $OpenBSD: xform.h,v 1.8 2001/08/28 12:20:43 ben Exp $ */
  3. /*-
  4. * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
  5. *
  6. * This code was written by Angelos D. Keromytis in Athens, Greece, in
  7. * February 2000. Network Security Technologies Inc. (NSTI) kindly
  8. * supported the development of this code.
  9. *
  10. * Copyright (c) 2000 Angelos D. Keromytis
  11. * Copyright (c) 2014 The FreeBSD Foundation
  12. * All rights reserved.
  13. *
  14. * Portions of this software were developed by John-Mark Gurney
  15. * under sponsorship of the FreeBSD Foundation and
  16. * Rubicon Communications, LLC (Netgate).
  17. *
  18. * Permission to use, copy, and modify this software without fee
  19. * is hereby granted, provided that this entire notice is included in
  20. * all source code copies of any software which is or includes a copy or
  21. * modification of this software.
  22. *
  23. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
  24. * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
  25. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
  26. * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
  27. * PURPOSE.
  28. */
  29. #ifndef _CRYPTO_XFORM_ENC_H_
  30. #define _CRYPTO_XFORM_ENC_H_
  31. #include <sys/malloc.h>
  32. #include <sys/errno.h>
  33. #include <crypto/rijndael/rijndael.h>
  34. #include <crypto/camellia/camellia.h>
  35. #include <opencrypto/cryptodev.h>
  36. #ifdef _STANDALONE
  37. #include <stand.h>
  38. #endif
  39. #define AESICM_BLOCKSIZE AES_BLOCK_LEN
  40. #define AES_XTS_BLOCKSIZE 16
  41. #define AES_XTS_IVSIZE 8
  42. #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */
  43. /* Declarations */
  44. struct enc_xform {
  45. int type;
  46. char *name;
  47. size_t ctxsize;
  48. uint16_t blocksize; /* Required input block size -- 1 for stream ciphers. */
  49. uint16_t native_blocksize; /* Used for stream ciphers. */
  50. uint16_t ivsize;
  51. uint16_t minkey, maxkey;
  52. /*
  53. * Encrypt/decrypt a single block. For stream ciphers this
  54. * encrypts/decrypts a single "native" block.
  55. */
  56. void (*encrypt) (void *, const uint8_t *, uint8_t *);
  57. void (*decrypt) (void *, const uint8_t *, uint8_t *);
  58. int (*setkey) (void *, const uint8_t *, int len);
  59. void (*reinit) (void *, const uint8_t *);
  60. /*
  61. * For stream ciphers, encrypt/decrypt the final partial block
  62. * of 'len' bytes.
  63. */
  64. void (*encrypt_last) (void *, const uint8_t *, uint8_t *, size_t len);
  65. void (*decrypt_last) (void *, const uint8_t *, uint8_t *, size_t len);
  66. };
  67. extern struct enc_xform enc_xform_null;
  68. extern struct enc_xform enc_xform_rijndael128;
  69. extern struct enc_xform enc_xform_aes_icm;
  70. extern struct enc_xform enc_xform_aes_nist_gcm;
  71. extern struct enc_xform enc_xform_aes_nist_gmac;
  72. extern struct enc_xform enc_xform_aes_xts;
  73. extern struct enc_xform enc_xform_camellia;
  74. extern struct enc_xform enc_xform_chacha20;
  75. extern struct enc_xform enc_xform_ccm;
  76. struct aes_icm_ctx {
  77. uint32_t ac_ek[4*(RIJNDAEL_MAXNR + 1)];
  78. /* ac_block is initialized to IV */
  79. uint8_t ac_block[AESICM_BLOCKSIZE];
  80. int ac_nr;
  81. };
  82. struct aes_xts_ctx {
  83. rijndael_ctx key1;
  84. rijndael_ctx key2;
  85. uint8_t tweak[AES_XTS_BLOCKSIZE];
  86. };
  87. #endif /* _CRYPTO_XFORM_ENC_H_ */