2
0

cbc_start.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. *
  9. * Tom St Denis, [email protected], http://libtomcrypt.org
  10. */
  11. #include "mycrypt.h"
  12. #ifdef CBC
  13. int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
  14. int keylen, int num_rounds, symmetric_CBC *cbc)
  15. {
  16. int x, err;
  17. _ARGCHK(IV != NULL);
  18. _ARGCHK(key != NULL);
  19. _ARGCHK(cbc != NULL);
  20. /* bad param? */
  21. if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
  22. return err;
  23. }
  24. /* setup cipher */
  25. if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {
  26. return err;
  27. }
  28. /* copy IV */
  29. cbc->blocklen = cipher_descriptor[cipher].block_length;
  30. cbc->cipher = cipher;
  31. for (x = 0; x < cbc->blocklen; x++) {
  32. cbc->IV[x] = IV[x];
  33. }
  34. return CRYPT_OK;
  35. }
  36. #endif