idea.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*!
  2. \ingroup IDEA
  3. \brief Generate the 52, 16-bit key sub-blocks from the 128 key.
  4. \return 0 Success
  5. \return BAD_FUNC_ARG Returns if idea or key is null, keySz is not equal to
  6. IDEA_KEY_SIZE, or dir is not IDEA_ENCRYPTION or IDEA_DECRYPTION.
  7. \param idea Pointer to Idea structure.
  8. \param key Pointer to key in memory.
  9. \param keySz Size of key.
  10. \param iv Value for IV in Idea structure. Can be null.
  11. \param dir Direction, either IDEA_ENCRYPTION or IDEA_DECRYPTION
  12. _Example_
  13. \code
  14. byte v_key[IDEA_KEY_SIZE] = { }; // Some Key
  15. Idea idea;
  16. int ret = wc_IdeaSetKey(&idea v_key, IDEA_KEY_SIZE, NULL, IDEA_ENCRYPTION);
  17. if (ret != 0)
  18. {
  19. // There was an error
  20. }
  21. \endcode
  22. \sa wc_IdeaSetIV
  23. */
  24. WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz,
  25. const byte *iv, int dir);
  26. /*!
  27. \ingroup IDEA
  28. \brief Sets the IV in an Idea key structure.
  29. \return 0 Success
  30. \return BAD_FUNC_ARG Returns if idea is null.
  31. \param idea Pointer to idea key structure.
  32. \param iv The IV value to set, can be null.
  33. _Example_
  34. \code
  35. Idea idea;
  36. // Initialize idea
  37. byte iv[] = { }; // Some IV
  38. int ret = wc_IdeaSetIV(&idea, iv);
  39. if(ret != 0)
  40. {
  41. // Some error occured
  42. }
  43. \endcode
  44. \sa wc_IdeaSetKey
  45. */
  46. WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv);
  47. /*!
  48. \ingroup IDEA
  49. \brief Encryption or decryption for a block (64 bits).
  50. \return 0 upon success.
  51. \return <0 an error occured
  52. \param idea Pointer to idea key structure.
  53. \param out Pointer to destination.
  54. \param in Pointer to input data to encrypt or decrypt.
  55. _Example_
  56. \code
  57. byte v_key[IDEA_KEY_SIZE] = { }; // Some Key
  58. byte data[IDEA_BLOCK_SIZE] = { }; // Some encrypted data
  59. Idea idea;
  60. wc_IdeaSetKey(&idea, v_key, IDEA_KEY_SIZE, NULL, IDEA_DECRYPTION);
  61. int ret = wc_IdeaCipher(&idea, data, data);
  62. if (ret != 0)
  63. {
  64. // There was an error
  65. }
  66. \endcode
  67. \sa wc_IdeaSetKey
  68. \sa wc_IdeaSetIV
  69. \sa wc_IdeaCbcEncrypt
  70. \sa wc_IdeaCbcDecrypt
  71. */
  72. WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte* out, const byte* in);
  73. /*!
  74. \ingroup IDEA
  75. \brief Encrypt data using IDEA CBC mode.
  76. \return 0 Success
  77. \return BAD_FUNC_ARG Returns if any arguments are null.
  78. \param idea Pointer to Idea key structure.
  79. \param out Pointer to destination for encryption.
  80. \param in Pointer to input for encryption.
  81. \param len length of input.
  82. _Example_
  83. \code
  84. Idea idea;
  85. // Initialize idea structure for encryption
  86. const char *message = "International Data Encryption Algorithm";
  87. byte msg_enc[40], msg_dec[40];
  88. memset(msg_enc, 0, sizeof(msg_enc));
  89. ret = wc_IdeaCbcEncrypt(&idea, msg_enc, (byte *)message,
  90. (word32)strlen(message)+1);
  91. if(ret != 0)
  92. {
  93. // Some error occured
  94. }
  95. \endcode
  96. \sa wc_IdeaCbcDecrypt
  97. \sa wc_IdeaCipher
  98. \sa wc_IdeaSetKey
  99. */
  100. WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out,
  101. const byte* in, word32 len);
  102. /*!
  103. \ingroup IDEA
  104. \brief Decrypt data using IDEA CBC mode.
  105. \return 0 Success
  106. \return BAD_FUNC_ARG Returns if any arguments are null.
  107. \param idea Pointer to Idea key structure.
  108. \param out Pointer to destination for encryption.
  109. \param in Pointer to input for encryption.
  110. \param len length of input.
  111. _Example_
  112. \code
  113. Idea idea;
  114. // Initialize idea structure for decryption
  115. const char *message = "International Data Encryption Algorithm";
  116. byte msg_enc[40], msg_dec[40];
  117. memset(msg_dec, 0, sizeof(msg_dec));
  118. ret = wc_IdeaCbcDecrypt(&idea, msg_dec, msg_enc,
  119. (word32)strlen(message)+1);
  120. if(ret != 0)
  121. {
  122. // Some error occured
  123. }
  124. \endcode
  125. \sa wc_IdeaCbcEncrypt
  126. \sa wc_IdeaCipher
  127. \sa wc_IdeaSetKey
  128. */
  129. WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out,
  130. const byte* in, word32 len);