1
0

camellia.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*!
  2. \ingroup Camellia
  3. \brief This function sets the key and initialization vector for a
  4. camellia object, initializing it for use as a cipher.
  5. \return 0 Returned upon successfully setting the key and initialization
  6. vector
  7. \return BAD_FUNC_ARG returned if there is an error processing one of
  8. the input arguments
  9. \return MEMORY_E returned if there is an error allocating memory with
  10. XMALLOC
  11. \param cam pointer to the camellia structure on which to set the key and iv
  12. \param key pointer to the buffer containing the 16, 24, or 32 byte key
  13. to use for encryption and decryption
  14. \param len length of the key passed in
  15. \param iv pointer to the buffer containing the 16 byte initialization
  16. vector for use with this camellia structure
  17. _Example_
  18. \code
  19. Camellia cam;
  20. byte key[32];
  21. // initialize key
  22. byte iv[16];
  23. // initialize iv
  24. if( wc_CamelliaSetKey(&cam, key, sizeof(key), iv) != 0) {
  25. // error initializing camellia structure
  26. }
  27. \endcode
  28. \sa wc_CamelliaEncryptDirect
  29. \sa wc_CamelliaDecryptDirect
  30. \sa wc_CamelliaCbcEncrypt
  31. \sa wc_CamelliaCbcDecrypt
  32. */
  33. int wc_CamelliaSetKey(Camellia* cam,
  34. const byte* key, word32 len, const byte* iv);
  35. /*!
  36. \ingroup Camellia
  37. \brief This function sets the initialization vector for a camellia object.
  38. \return 0 Returned upon successfully setting the key and initialization
  39. vector
  40. \return BAD_FUNC_ARG returned if there is an error processing one of the
  41. input arguments
  42. \param cam pointer to the camellia structure on which to set the iv
  43. \param iv pointer to the buffer containing the 16 byte initialization
  44. vector for use with this camellia structure
  45. _Example_
  46. \code
  47. Camellia cam;
  48. byte iv[16];
  49. // initialize iv
  50. if( wc_CamelliaSetIV(&cam, iv) != 0) {
  51. // error initializing camellia structure
  52. }
  53. \endcode
  54. \sa wc_CamelliaSetKey
  55. */
  56. int wc_CamelliaSetIV(Camellia* cam, const byte* iv);
  57. /*!
  58. \ingroup Camellia
  59. \brief This function does a one-block encrypt using the provided camellia
  60. object. It parses the first 16 byte block from the buffer in and stores
  61. the encrypted result in the buffer out. Before using this function, one
  62. should initialize the camellia object using wc_CamelliaSetKey.
  63. \return none No returns.
  64. \param cam pointer to the camellia structure to use for encryption
  65. \param out pointer to the buffer in which to store the encrypted block
  66. \param in pointer to the buffer containing the plaintext block to encrypt
  67. _Example_
  68. \code
  69. Camellia cam;
  70. // initialize cam structure with key and iv
  71. byte plain[] = { // initialize with message to encrypt };
  72. byte cipher[16];
  73. wc_CamelliaEncryptDirect(&ca, cipher, plain);
  74. \endcode
  75. \sa wc_CamelliaDecryptDirect
  76. */
  77. int wc_CamelliaEncryptDirect(Camellia* cam, byte* out,
  78. const byte* in);
  79. /*!
  80. \ingroup Camellia
  81. \brief This function does a one-block decrypt using the provided camellia
  82. object. It parses the first 16 byte block from the buffer in, decrypts it,
  83. and stores the result in the buffer out. Before using this function, one
  84. should initialize the camellia object using wc_CamelliaSetKey.
  85. \return none No returns.
  86. \param cam pointer to the camellia structure to use for encryption
  87. \param out pointer to the buffer in which to store the decrypted
  88. plaintext block
  89. \param in pointer to the buffer containing the ciphertext block to decrypt
  90. _Example_
  91. \code
  92. Camellia cam;
  93. // initialize cam structure with key and iv
  94. byte cipher[] = { // initialize with encrypted message to decrypt };
  95. byte decrypted[16];
  96. wc_CamelliaDecryptDirect(&cam, decrypted, cipher);
  97. \endcode
  98. \sa wc_CamelliaEncryptDirect
  99. */
  100. int wc_CamelliaDecryptDirect(Camellia* cam, byte* out,
  101. const byte* in);
  102. /*!
  103. \ingroup Camellia
  104. \brief This function encrypts the plaintext from the buffer in and
  105. stores the output in the buffer out. It performs this encryption
  106. using Camellia with Cipher Block Chaining (CBC).
  107. \return none No returns.
  108. \param cam pointer to the camellia structure to use for encryption
  109. \param out pointer to the buffer in which to store the encrypted ciphertext
  110. \param in pointer to the buffer containing the plaintext to encrypt
  111. \param sz the size of the message to encrypt
  112. _Example_
  113. \code
  114. Camellia cam;
  115. // initialize cam structure with key and iv
  116. byte plain[] = { // initialize with encrypted message to decrypt };
  117. byte cipher[sizeof(plain)];
  118. wc_CamelliaCbcEncrypt(&cam, cipher, plain, sizeof(plain));
  119. \endcode
  120. \sa wc_CamelliaCbcDecrypt
  121. */
  122. int wc_CamelliaCbcEncrypt(Camellia* cam,
  123. byte* out, const byte* in, word32 sz);
  124. /*!
  125. \ingroup Camellia
  126. \brief This function decrypts the ciphertext from the buffer in and
  127. stores the output in the buffer out. It performs this decryption using
  128. Camellia with Cipher Block Chaining (CBC).
  129. \return none No returns.
  130. \param cam pointer to the camellia structure to use for encryption
  131. \param out pointer to the buffer in which to store the decrypted message
  132. \param in pointer to the buffer containing the encrypted ciphertext
  133. \param sz the size of the message to encrypt
  134. _Example_
  135. \code
  136. Camellia cam;
  137. // initialize cam structure with key and iv
  138. byte cipher[] = { // initialize with encrypted message to decrypt };
  139. byte decrypted[sizeof(cipher)];
  140. wc_CamelliaCbcDecrypt(&cam, decrypted, cipher, sizeof(cipher));
  141. \endcode
  142. \sa wc_CamelliaCbcEncrypt
  143. */
  144. int wc_CamelliaCbcDecrypt(Camellia* cam,
  145. byte* out, const byte* in, word32 sz);