Shannon.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef SHANNON_H
  2. #define SHANNON_H
  3. #include <cstdint>
  4. #include <vector>
  5. class Shannon
  6. {
  7. public:
  8. static constexpr unsigned int N = 16;
  9. void key(const std::vector<uint8_t> &key); /* set key */
  10. void nonce(const std::vector<uint8_t> &nonce); /* set Init Vector */
  11. void stream(std::vector<uint8_t> &buf); /* stream cipher */
  12. void maconly(std::vector<uint8_t> &buf); /* accumulate MAC */
  13. void encrypt(std::vector<uint8_t> &buf); /* encrypt + MAC */
  14. void decrypt(std::vector<uint8_t> &buf); /* finalize + MAC */
  15. void finish(std::vector<uint8_t> &buf); /* finalise MAC */
  16. private:
  17. static constexpr unsigned int FOLD = Shannon::N;
  18. static constexpr unsigned int INITKONST = 0x6996c53a;
  19. static constexpr unsigned int KEYP = 13;
  20. uint32_t R[Shannon::N];
  21. uint32_t CRC[Shannon::N];
  22. uint32_t initR[Shannon::N];
  23. uint32_t konst;
  24. uint32_t sbuf;
  25. uint32_t mbuf;
  26. int nbuf;
  27. static uint32_t sbox1(uint32_t w);
  28. static uint32_t sbox2(uint32_t w);
  29. void cycle();
  30. void crcfunc(uint32_t i);
  31. void macfunc(uint32_t i);
  32. void initState();
  33. void saveState();
  34. void reloadState();
  35. void genkonst();
  36. void diffuse();
  37. void loadKey(const std::vector<uint8_t> &key);
  38. };
  39. #endif