desmodes.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "os.h"
  10. #include <libsec.h>
  11. /*
  12. * these routines use the 64bit format for
  13. * DES keys.
  14. */
  15. void
  16. setupDESstate(DESstate *s, uint8_t key[8], uint8_t *ivec)
  17. {
  18. memset(s, 0, sizeof(*s));
  19. memmove(s->key, key, sizeof(s->key));
  20. des_key_setup(key, s->expanded);
  21. if(ivec)
  22. memmove(s->ivec, ivec, 8);
  23. s->setup = 0xdeadbeef;
  24. }
  25. void
  26. setupDES3state(DES3state *s, uint8_t key[3][8], uint8_t *ivec)
  27. {
  28. memset(s, 0, sizeof(*s));
  29. memmove(s->key, key, sizeof(s->key));
  30. des_key_setup(key[0], s->expanded[0]);
  31. des_key_setup(key[1], s->expanded[1]);
  32. des_key_setup(key[2], s->expanded[2]);
  33. if(ivec)
  34. memmove(s->ivec, ivec, 8);
  35. s->setup = 0xdeadbeef;
  36. }