speck.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef SPECK_HEADER
  2. #define SPECK_HEADER
  3. #define ER64(x,y,k) (x=ROTR64(x,8), x+=y, x^=k, y=ROTL64(y,3), y^=x)
  4. #define DR64(x,y,k) (y^=x, y=ROTR64(y,3), x^=k, x-=y, x=ROTL64(x,8))
  5. #define ROTL64(x,r) (((x)<<(r)) | (x>>(64-(r))))
  6. #define ROTR64(x,r) (((x)>>(r)) | ((x)<<(64-(r))))
  7. // The same stuff for 32 bit
  8. #define ROTL32(x,r) (((x)<<(r)) | (x>>(32-(r))))
  9. #define ROTR32(x,r) (((x)>>(r)) | ((x)<<(32-(r))))
  10. #define ER32(x,y,k) (x=ROTR32(x,8), x+=y, x^=k, y=ROTL32(y,3), y^=x)
  11. #define DR32(x,y,k) (y^=x, y=ROTR32(y,3), x^=k, x-=y, x=ROTL32(x,8))
  12. // The same stuff for 16 bit
  13. #define ROTL16(x,r) (((x)<<(r)) | (x>>(16-(r))))
  14. #define ROTR16(x,r) (((x)>>(r)) | ((x)<<(16-(r))))
  15. #define ER16(x,y,k) (x=ROTR16(x,7), x+=y, x^=k, y=ROTL16(y,2), y^=x)
  16. #define DR16(x,y,k) (y^=x, y=ROTR16(y,2), x^=k, x-=y, x=ROTL16(x,7))
  17. #define u8 uint8_t
  18. #define u16 uint16_t
  19. #define u32 uint32_t
  20. #define u64 uint64_t
  21. void Words64ToBytes(u64 words[],u8 bytes[],int numwords);
  22. void BytesToWords64(u8 bytes[],u64 words[],int numbytes);
  23. void Speck128256KeySchedule(u64 K[],u64 rk[]);
  24. void Speck128256Encrypt(u64 Pt[],u64 Ct[],u64 rk[]);
  25. void Speck128256Decrypt(u64 Pt[],u64 Ct[],u64 rk[]);
  26. void EncryptBlock(u8 pt[], u8 k[], u8 ct[]);
  27. void Speck3264_EncryptBlock(u8 pt[], u8 k[], u8 ct[]);
  28. // 32 bit versions functions
  29. void Words32ToBytes(u32 words[],u8 bytes[],int numwords);
  30. void BytesToWords32(u8 bytes[],u32 words[],int numbytes);
  31. void Words16ToBytes(u16 words[],u8 bytes[],int numwords);
  32. void BytesToWords16(u8 bytes[],u16 words[],int numbytes);
  33. void Speck3264KeySchedule(u16 K[],u16 rk[]);
  34. void Speck3264Encrypt(u16 Pt[],u16 Ct[],u16 rk[]);
  35. void Speck3264Decrypt(u16 Pt[],u16 Ct[],u16 rk[]);
  36. #endif