crypt_register_cipher.c 921 B

123456789101112131415161718192021222324252627282930313233343536
  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. int register_cipher(const struct _cipher_descriptor *cipher)
  13. {
  14. int x;
  15. _ARGCHK(cipher != NULL);
  16. /* is it already registered? */
  17. for (x = 0; x < TAB_SIZE; x++) {
  18. if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
  19. return x;
  20. }
  21. }
  22. /* find a blank spot */
  23. for (x = 0; x < TAB_SIZE; x++) {
  24. if (cipher_descriptor[x].name == NULL) {
  25. XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct _cipher_descriptor));
  26. return x;
  27. }
  28. }
  29. /* no spot */
  30. return -1;
  31. }