ofb_start.c 1008 B

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