cfb_start.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 CFB
  13. int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
  14. int keylen, int num_rounds, symmetric_CFB *cfb)
  15. {
  16. int x, err;
  17. _ARGCHK(IV != NULL);
  18. _ARGCHK(key != NULL);
  19. _ARGCHK(cfb != NULL);
  20. if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
  21. return err;
  22. }
  23. /* copy data */
  24. cfb->cipher = cipher;
  25. cfb->blocklen = cipher_descriptor[cipher].block_length;
  26. for (x = 0; x < cfb->blocklen; x++)
  27. cfb->IV[x] = IV[x];
  28. /* init the cipher */
  29. if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
  30. return err;
  31. }
  32. /* encrypt the IV */
  33. cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
  34. cfb->padlen = 0;
  35. return CRYPT_OK;
  36. }
  37. #endif