Browse Source

Updated to libtomcrypt 1.18.2.3474ca3

Brucey 2 years ago
parent
commit
a912c37a2a
100 changed files with 2413 additions and 1017 deletions
  1. 1 0
      .gitignore
  2. 34 3
      aescipher.mod/aescipher.bmx
  3. 5 0
      aescipher.mod/common.bmx
  4. 33 2
      anubiscipher.mod/anubiscipher.bmx
  5. 6 1
      anubiscipher.mod/common.bmx
  6. 1 1
      anubiscipher.mod/glue.c
  7. 1 1
      blake2bdigest.mod/blake2bdigest.bmx
  8. 1 1
      blake2bdigest.mod/common.bmx
  9. 1 1
      blake2bdigest.mod/glue.c
  10. 33 2
      blowfishcipher.mod/blowfishcipher.bmx
  11. 6 1
      blowfishcipher.mod/common.bmx
  12. 1 1
      blowfishcipher.mod/glue.c
  13. 33 2
      camelliacipher.mod/camelliacipher.bmx
  14. 6 1
      camelliacipher.mod/common.bmx
  15. 1 1
      camelliacipher.mod/glue.c
  16. 33 2
      cast5cipher.mod/cast5cipher.bmx
  17. 6 1
      cast5cipher.mod/common.bmx
  18. 1 1
      cast5cipher.mod/glue.c
  19. 1 1
      cbcmode.mod/cbcmode.bmx
  20. 1 1
      cbcmode.mod/common.bmx
  21. 1 1
      cbcmode.mod/glue.c
  22. 1 1
      cfbmode.mod/cfbmode.bmx
  23. 1 1
      cfbmode.mod/common.bmx
  24. 1 1
      cfbmode.mod/glue.c
  25. 107 7
      cipher.mod/cipher.bmx
  26. 9 1
      cipher.mod/common.bmx
  27. 1 0
      cipher.mod/doc/intro.bbdoc
  28. 9 1
      cipher.mod/glue.c
  29. 1 1
      crc32.mod/common.bmx
  30. 1 1
      crc32.mod/crc32.bmx
  31. 1 1
      crc32.mod/glue.c
  32. 1 1
      crypto.mod/common.bmx
  33. 1 1
      crypto.mod/crypto.bmx
  34. 1 1
      crypto.mod/glue.c
  35. 8 2
      ctrmode.mod/common.bmx
  36. 2 8
      ctrmode.mod/ctrmode.bmx
  37. 1 1
      ctrmode.mod/doc/tctrciphermode.bmx
  38. 1 1
      ctrmode.mod/glue.c
  39. 11 1
      descipher.mod/common.bmx
  40. 65 3
      descipher.mod/descipher.bmx
  41. 1 1
      descipher.mod/glue.c
  42. 2 2
      digest.mod/common.bmx
  43. 4 21
      digest.mod/digest.bmx
  44. 1 1
      digest.mod/glue.c
  45. 1 1
      digest.mod/source.bmx
  46. 1 1
      ecbmode.mod/common.bmx
  47. 1 1
      ecbmode.mod/ecbmode.bmx
  48. 1 1
      ecbmode.mod/glue.c
  49. 1 1
      f8mode.mod/common.bmx
  50. 1 1
      f8mode.mod/f8mode.bmx
  51. 1 1
      f8mode.mod/glue.c
  52. 1 1
      gcmauthmode.mod/common.bmx
  53. 1 1
      gcmauthmode.mod/gcmauthmode.bmx
  54. 6 1
      ideacipher.mod/common.bmx
  55. 1 1
      ideacipher.mod/glue.c
  56. 33 2
      ideacipher.mod/ideacipher.bmx
  57. 6 1
      kasumicipher.mod/common.bmx
  58. 1 1
      kasumicipher.mod/glue.c
  59. 33 2
      kasumicipher.mod/kasumicipher.bmx
  60. 6 1
      khazadcipher.mod/common.bmx
  61. 1 1
      khazadcipher.mod/glue.c
  62. 33 2
      khazadcipher.mod/khazadcipher.bmx
  63. 6 1
      kseedcipher.mod/common.bmx
  64. 1 1
      kseedcipher.mod/glue.c
  65. 33 2
      kseedcipher.mod/kseedcipher.bmx
  66. 1 1
      libhydrogen.mod/libhydrogen.bmx
  67. 1 1
      libhydrogen.mod/source.bmx
  68. 158 0
      libtomcrypt.mod/common.bmx
  69. 12 0
      libtomcrypt.mod/libtomcrypt.bmx
  70. 26 29
      libtomcrypt.mod/libtomcrypt/LICENSE
  71. 7 17
      libtomcrypt.mod/libtomcrypt/src/ciphers/aes/aes.c
  72. 4 14
      libtomcrypt.mod/libtomcrypt/src/ciphers/aes/aes_tab.c
  73. 14 14
      libtomcrypt.mod/libtomcrypt/src/ciphers/anubis.c
  74. 154 91
      libtomcrypt.mod/libtomcrypt/src/ciphers/blowfish.c
  75. 6 12
      libtomcrypt.mod/libtomcrypt/src/ciphers/camellia.c
  76. 11 27
      libtomcrypt.mod/libtomcrypt/src/ciphers/cast5.c
  77. 296 290
      libtomcrypt.mod/libtomcrypt/src/ciphers/des.c
  78. 47 57
      libtomcrypt.mod/libtomcrypt/src/ciphers/idea.c
  79. 2 12
      libtomcrypt.mod/libtomcrypt/src/ciphers/kasumi.c
  80. 2 12
      libtomcrypt.mod/libtomcrypt/src/ciphers/khazad.c
  81. 2 12
      libtomcrypt.mod/libtomcrypt/src/ciphers/kseed.c
  82. 29 39
      libtomcrypt.mod/libtomcrypt/src/ciphers/multi2.c
  83. 6 16
      libtomcrypt.mod/libtomcrypt/src/ciphers/noekeon.c
  84. 6 16
      libtomcrypt.mod/libtomcrypt/src/ciphers/rc2.c
  85. 16 18
      libtomcrypt.mod/libtomcrypt/src/ciphers/rc5.c
  86. 8 18
      libtomcrypt.mod/libtomcrypt/src/ciphers/rc6.c
  87. 15 25
      libtomcrypt.mod/libtomcrypt/src/ciphers/safer/safer.c
  88. 4 14
      libtomcrypt.mod/libtomcrypt/src/ciphers/safer/safer_tab.c
  89. 19 21
      libtomcrypt.mod/libtomcrypt/src/ciphers/safer/saferp.c
  90. 76 86
      libtomcrypt.mod/libtomcrypt/src/ciphers/serpent.c
  91. 6 16
      libtomcrypt.mod/libtomcrypt/src/ciphers/skipjack.c
  92. 209 0
      libtomcrypt.mod/libtomcrypt/src/ciphers/tea.c
  93. 13 23
      libtomcrypt.mod/libtomcrypt/src/ciphers/twofish/twofish.c
  94. 4 14
      libtomcrypt.mod/libtomcrypt/src/ciphers/twofish/twofish_tab.c
  95. 3 13
      libtomcrypt.mod/libtomcrypt/src/ciphers/xtea.c
  96. 53 0
      libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_add_aad.c
  97. 106 0
      libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_add_nonce.c
  98. 55 0
      libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_done.c
  99. 64 0
      libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_init.c
  100. 372 0
      libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_memory.c

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@
 *.i
 *.i
 *.i2
 *.i2
 *.exe
 *.exe
+.DS_Store

+ 34 - 3
aescipher.mod/aescipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TAESCipherFactory(bmx_crypto_aes_register())
 New TAESCipherFactory(bmx_crypto_aes_register())
 
 
-Type TAESCipher Extends TCipher
+Type TAESCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_aes_keysize(key)
 		Return bmx_crypto_aes_keysize(key)
@@ -44,7 +44,38 @@ Type TAESCipher Extends TCipher
 	Method Name:String() Override
 	Method Name:String() Override
 		Return "aes"
 		Return "aes"
 	End Method
 	End Method
-	
+
+	Method BlockSize:Int() Override
+		Return 16
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = rijndael_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return rijndael_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return rijndael_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return rijndael_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return rijndael_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		rijndael_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TAESCipherFactory Extends TCipherFactory
 Type TAESCipherFactory Extends TCipherFactory

+ 5 - 0
aescipher.mod/common.bmx

@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_aes_register:Int()
 	Function bmx_crypto_aes_register:Int()
 	Function bmx_crypto_aes_keysize:Int(key:Int)
 	Function bmx_crypto_aes_keysize:Int(key:Int)
 
 
+	Function rijndael_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function rijndael_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function rijndael_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function rijndael_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 33 - 2
anubiscipher.mod/anubiscipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -36,7 +36,7 @@ Import "common.bmx"
 
 
 New TAnubisCipherFactory(bmx_crypto_anubis_register())
 New TAnubisCipherFactory(bmx_crypto_anubis_register())
 
 
-Type TAnubisCipher Extends TCipher
+Type TAnubisCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_anubis_keysize(key)
 		Return bmx_crypto_anubis_keysize(key)
@@ -46,6 +46,37 @@ Type TAnubisCipher Extends TCipher
 		Return "anubis"
 		Return "anubis"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 16
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = anubis_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return anubis_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return anubis_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return anubis_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return anubis_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		anubis_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TAnubisCipherFactory Extends TCipherFactory
 Type TAnubisCipherFactory Extends TCipherFactory

+ 6 - 1
anubiscipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_anubis_register:Int()
 	Function bmx_crypto_anubis_register:Int()
 	Function bmx_crypto_anubis_keysize:Int(key:Int)
 	Function bmx_crypto_anubis_keysize:Int(key:Int)
 
 
+	Function anubis_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function anubis_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function anubis_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function anubis_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
anubiscipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
blake2bdigest.mod/blake2bdigest.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
blake2bdigest.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
blake2bdigest.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
blowfishcipher.mod/blowfishcipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TBlowfishCipherFactory(bmx_crypto_blowfish_register())
 New TBlowfishCipherFactory(bmx_crypto_blowfish_register())
 
 
-Type TBlowfishCipher Extends TCipher
+Type TBlowfishCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_blowfish_keysize(key)
 		Return bmx_crypto_blowfish_keysize(key)
@@ -45,6 +45,37 @@ Type TBlowfishCipher Extends TCipher
 		Return "blowfish"
 		Return "blowfish"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = blowfish_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return blowfish_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return blowfish_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return blowfish_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return blowfish_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		blowfish_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TBlowfishCipherFactory Extends TCipherFactory
 Type TBlowfishCipherFactory Extends TCipherFactory

+ 6 - 1
blowfishcipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_blowfish_register:Int()
 	Function bmx_crypto_blowfish_register:Int()
 	Function bmx_crypto_blowfish_keysize:Int(key:Int)
 	Function bmx_crypto_blowfish_keysize:Int(key:Int)
 
 
+	Function blowfish_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function blowfish_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function blowfish_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function blowfish_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
blowfishcipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
camelliacipher.mod/camelliacipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TCamelliaCipherFactory(bmx_crypto_camellia_register())
 New TCamelliaCipherFactory(bmx_crypto_camellia_register())
 
 
-Type TCamelliaCipher Extends TCipher
+Type TCamelliaCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_camellia_keysize(key)
 		Return bmx_crypto_camellia_keysize(key)
@@ -45,6 +45,37 @@ Type TCamelliaCipher Extends TCipher
 		Return "camellia"
 		Return "camellia"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 16
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = camellia_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return camellia_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return camellia_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return camellia_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return camellia_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		camellia_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TCamelliaCipherFactory Extends TCipherFactory
 Type TCamelliaCipherFactory Extends TCipherFactory

+ 6 - 1
camelliacipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_camellia_register:Int()
 	Function bmx_crypto_camellia_register:Int()
 	Function bmx_crypto_camellia_keysize:Int(key:Int)
 	Function bmx_crypto_camellia_keysize:Int(key:Int)
 
 
+	Function camellia_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function camellia_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function camellia_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function camellia_done(skey:Byte Ptr)
+	
 End Extern
 End Extern

+ 1 - 1
camelliacipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
cast5cipher.mod/cast5cipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TCast5CipherFactory(bmx_crypto_cast5_register())
 New TCast5CipherFactory(bmx_crypto_cast5_register())
 
 
-Type TCast5Cipher Extends TCipher
+Type TCast5Cipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_cast5_keysize(key)
 		Return bmx_crypto_cast5_keysize(key)
@@ -45,6 +45,37 @@ Type TCast5Cipher Extends TCipher
 		Return "cast5"
 		Return "cast5"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = cast5_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return cast5_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return cast5_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return cast5_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return cast5_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		cast5_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TCast5CipherFactory Extends TCipherFactory
 Type TCast5CipherFactory Extends TCipherFactory

+ 6 - 1
cast5cipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_cast5_register:Int()
 	Function bmx_crypto_cast5_register:Int()
 	Function bmx_crypto_cast5_keysize:Int(key:Int)
 	Function bmx_crypto_cast5_keysize:Int(key:Int)
 
 
+	Function cast5_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function cast5_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function cast5_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function cast5_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
cast5cipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cbcmode.mod/cbcmode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cbcmode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cbcmode.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cfbmode.mod/cfbmode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cfbmode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
cfbmode.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 107 - 7
cipher.mod/cipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,17 +32,53 @@ Private
 Global _cipher_factories:TCipherFactory
 Global _cipher_factories:TCipherFactory
 Public
 Public
 
 
+Rem
+bbdoc: Gets a cipher of the specified @name.
+about: A #TNoSuchAlgorithmException is thrown if the requested cipher is not available.
+End Rem
+Function GetCipher:TCipher(name:String)
+	Local c:TCipher = TCipher.Find(name)
+
+	If Not c Then
+		Throw New TNoSuchAlgorithmException("Cipher not available : " + name)
+	End If
+	Return c
+End Function
+
+Rem
+bbdoc: Gets a block cipher of the specified @name.
+about: A #TNoSuchAlgorithmException is thrown if the requested block cipher is not available.
+End Rem
+Function GetBlockCipher:TBlockCipher(name:String)
+	Local c:TBlockCipher = TBlockCipher(GetCipher(name))
+
+	If Not c Then
+		Throw New TNoSuchAlgorithmException("Block cipher not available : " + name)
+	End If
+	Return c
+End Function
+
+Rem
+bbdoc: Gets a stream cipher of the specified @name.
+about: A #TNoSuchAlgorithmException is thrown if the requested stream cipher is not available.
+End Rem
+Function GetStreamCipher:TStreamCipher(name:String)
+	Local c:TStreamCipher = TStreamCipher(GetCipher(name))
+
+	If Not c Then
+		Throw New TNoSuchAlgorithmException("Stream cipher not available : " + name)
+	End If
+	Return c
+End Function
+
 Rem
 Rem
 bbdoc: Cipher base type.
 bbdoc: Cipher base type.
 End Rem
 End Rem
 Type TCipher
 Type TCipher
 
 
+	Field keyPtr:Byte Ptr
 	Field index:Int
 	Field index:Int
 	
 	
-	Method New(index:Int)
-		Self.index = index
-	End Method
-
 	Rem
 	Rem
 	bbdoc: Returns a list of all registered ciphers.
 	bbdoc: Returns a list of all registered ciphers.
 	End Rem
 	End Rem
@@ -70,16 +106,80 @@ Type TCipher
 	End Function
 	End Function
 
 
 	Rem
 	Rem
-	bbdoc: Returns the appropriate key size for @size.
+	bbdoc: Determines the appropriate key size for @size.
+	returns: The appropriate key size, or -1 if the provided @size was not acceptable.
 	about: Rounds the input keysize @size down to the next appropriate key size for use with the cipher.
 	about: Rounds the input keysize @size down to the next appropriate key size for use with the cipher.
 	End Rem
 	End Rem
 	Method KeySize:Int(size:Int) Abstract
 	Method KeySize:Int(size:Int) Abstract
-	
+
 	Rem
 	Rem
 	bbdoc: Returns the name of the cipher.
 	bbdoc: Returns the name of the cipher.
 	End Rem
 	End Rem
 	Method Name:String() Abstract
 	Method Name:String() Abstract
 	
 	
+	Rem
+	bbdoc: When you are finished with a cipher you can de–initialize it with the done method.
+	End Rem
+	Method Done() Abstract
+
+End Type
+
+Type TBlockCipher Extends TCipher
+
+	Method New(index:Int)
+		keyPtr = bmx_crypto_symmetric_key_new()
+		Self.index = index
+	End Method
+
+	Rem
+	bbdoc: The block size for this cipher.
+	End Rem
+	Method BlockSize:Int() Abstract
+	
+	Rem
+	bbdoc: Sets up the cipher to be used with a given number of @rounds and a given @key.
+	End Rem
+	Method Setup:Int(key:String, rounds:Int = 0) Abstract
+
+	Rem
+	bbdoc: Sets up the cipher to be used with a given number of @rounds and a given @key.
+	End Rem
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Abstract
+
+	Rem
+	bbdoc: Sets up the cipher to be used with a given number of @rounds and a given key length.
+	End Rem
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Abstract
+
+	Rem
+	bbdoc: Encrypts a single block of text, @pt, storing the result in the @ct buffer.
+	about: It is possible that the input and output buffer are the same buffer.
+	The size of the block can be determined with #BlockSize.
+	End Rem
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Abstract
+
+	Rem
+	bbdoc: Decrypts a single block of text, @ct, storing the result in the @pt buffer.
+	about: It is possible that the input and output buffer are the same buffer.
+	The size of the block can be determined with #BlockSize.
+	End Rem
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Abstract
+
+	Method Delete()
+		If keyPtr Then
+			bmx_crypto_symmetric_key_free(keyPtr)
+			keyPtr = Null
+		End If
+	End Method
+
+End Type
+
+Type TStreamCipher Extends TCipher
+
+	Method New(index:Int)
+		Self.index = index
+	End Method
+
 End Type
 End Type
 
 
 Rem
 Rem

+ 9 - 1
cipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -20,6 +20,7 @@
 SuperStrict
 SuperStrict
 
 
 Import Crypto.libtomcrypt
 Import Crypto.libtomcrypt
+Import Crypto.PRNG
 Import pub.stdc
 Import pub.stdc
 
 
 Import "../libtomcrypt.mod/libtomcrypt/src/headers/*.h"
 Import "../libtomcrypt.mod/libtomcrypt/src/headers/*.h"
@@ -39,6 +40,8 @@ Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_register_cipher.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_register_hash.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_register_hash.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_sizes.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_sizes.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c"
 Import "../libtomcrypt.mod/libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c"
+Import "../libtomcrypt.mod/libtomcrypt/src/misc/padding/padding_pad.c"
+Import "../libtomcrypt.mod/libtomcrypt/src/misc/padding/padding_depad.c"
 
 
 
 
 Import "glue.c"
 Import "glue.c"
@@ -48,4 +51,9 @@ Extern
 	Function bmx_crypto_listCiphers:String[]()
 	Function bmx_crypto_listCiphers:String[]()
 	Function bmx_crypto_findCipher:Int(name:String)
 	Function bmx_crypto_findCipher:Int(name:String)
 	
 	
+	Function bmx_crypto_symmetric_key_new:Byte Ptr()
+	Function bmx_crypto_symmetric_key_free(handle:Byte Ptr)
+
+	Function padding_pad:Int(data:Byte Ptr, length:ULongInt, paddedLength:ULongInt Var, mode:ULongInt)
+	Function padding_depad:Int(data:Byte Ptr, length:ULongInt Var, mode:ULongInt)
 End Extern
 End Extern

+ 1 - 0
cipher.mod/doc/intro.bbdoc

@@ -3,6 +3,7 @@
 | Name          | Block Size (bytes) | Key Range (bytes) | Rounds |
 | Name          | Block Size (bytes) | Key Range (bytes) | Rounds |
 |---|---|---|---|
 |---|---|---|---|
 | #Crypto.BlowfishCipher   | 8  | 8 ... 56   | 16 |
 | #Crypto.BlowfishCipher   | 8  | 8 ... 56   | 16 |
+| #Crypto.TeaCipher        | 8  | 16         | 32 |
 | #Crypto.XteaCipher       | 8  | 16         | 32 |
 | #Crypto.XteaCipher       | 8  | 16         | 32 |
 | #Crypto.AESCipher        | 16 | 16, 24, 32 | 10, 12, 14 |
 | #Crypto.AESCipher        | 16 | 16, 24, 32 | 10, 12, 14 |
 | #Crypto.TwofishCipher    | 16 | 16, 24, 32 | 16 |
 | #Crypto.TwofishCipher    | 16 | 16, 24, 32 | 16 |

+ 9 - 1
cipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages
@@ -58,3 +58,11 @@ int bmx_crypto_findCipher(BBString * name) {
 	bbMemFree(n);
 	bbMemFree(n);
 	return res;
 	return res;
 }
 }
+
+symmetric_key * bmx_crypto_symmetric_key_new() {
+	return (symmetric_key*)malloc(sizeof(symmetric_key));
+}
+
+void bmx_crypto_symmetric_key_free(symmetric_key * key) {
+	free(key);
+}

+ 1 - 1
crc32.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
crc32.mod/crc32.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
crc32.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
crypto.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-' Copyright (c) 2019-2020 Bruce A Henderson
+' Copyright (c) 2019-2022 Bruce A Henderson
 '
 '
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' purpose with or without fee is hereby granted, provided that the above
 ' purpose with or without fee is hereby granted, provided that the above

+ 1 - 1
crypto.mod/crypto.bmx

@@ -1,5 +1,5 @@
 '
 '
-' Copyright (c) 2019-2020 Bruce A Henderson
+' Copyright (c) 2019-2022 Bruce A Henderson
 '
 '
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' purpose with or without fee is hereby granted, provided that the above
 ' purpose with or without fee is hereby granted, provided that the above

+ 1 - 1
crypto.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2019-2020 Bruce A Henderson
+ * Copyright (c) 2019-2022 Bruce A Henderson
  *
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * purpose with or without fee is hereby granted, provided that the above

+ 8 - 2
ctrmode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -33,7 +33,7 @@ Import "glue.c"
 
 
 Extern
 Extern
 
 
-		Function bmx_crypto_ctr_start:Byte Ptr(index:Int, iv:Byte Ptr, key:Byte Ptr, keylen:Int, numRounds:Int, counterMode:Int, res:Int Var)
+		Function bmx_crypto_ctr_start:Byte Ptr(index:Int, iv:Byte Ptr, key:Byte Ptr, keylen:Int, numRounds:Int, counterMode:ECTRCounterMode, res:Int Var)
 		Function bmx_crypto_ctr_encrypt:Int(handle:Byte Ptr, pt:Byte Ptr, ct:Byte Ptr, length:UInt)
 		Function bmx_crypto_ctr_encrypt:Int(handle:Byte Ptr, pt:Byte Ptr, ct:Byte Ptr, length:UInt)
 		Function bmx_crypto_ctr_decrypt:Int(handle:Byte Ptr, ct:Byte Ptr, pt:Byte Ptr, length:UInt)
 		Function bmx_crypto_ctr_decrypt:Int(handle:Byte Ptr, ct:Byte Ptr, pt:Byte Ptr, length:UInt)
 		Function bmx_crypto_ctr_getiv:Int(handle:Byte Ptr, IV:Byte Ptr, length:UInt Var)
 		Function bmx_crypto_ctr_getiv:Int(handle:Byte Ptr, IV:Byte Ptr, length:UInt Var)
@@ -41,3 +41,9 @@ Extern
 		Function bmx_crypto_ctr_done:Int(handle:Byte Ptr)
 		Function bmx_crypto_ctr_done:Int(handle:Byte Ptr)
 		
 		
 End Extern
 End Extern
+
+Enum ECTRCounterMode
+	LITTLE_ENDIAN = $0000
+	BIG_ENDIAN = $1000
+	RFC3686 = $2000
+End Enum

+ 2 - 8
ctrmode.mod/ctrmode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -40,12 +40,6 @@ ModuleInfo "CC_OPTS: -DLTC_NO_TEST -DLTC_NO_FILE -DLTC_CTR_MODE"
 
 
 Import "common.bmx"
 Import "common.bmx"
 
 
-Enum ECTRCounterMode
-	LITTLE_ENDIAN = $0000
-	BIG_ENDIAN = $1000
-	RFC3686 = $2000
-End Enum
-
 Rem
 Rem
 bbdoc: CTR Cipher Mode
 bbdoc: CTR Cipher Mode
 about: A symmetric mode block cipher.
 about: A symmetric mode block cipher.
@@ -67,7 +61,7 @@ Type TCTRCipherMode Extends TCipherMode
 	It also supports variable length counters for CTR mode. The (optional) counter length is specified by OR'ing the octet length of
 	It also supports variable length counters for CTR mode. The (optional) counter length is specified by OR'ing the octet length of
 	the counter against the @counterMode parameter. The default, zero, indicates that a full block length counter will be used.
 	the counter against the @counterMode parameter. The default, zero, indicates that a full block length counter will be used.
 	End Rem
 	End Rem
-	Method Start:Int(cipher:TCipher, iv:Byte Ptr, key:Byte Ptr, keylen:Int, numRounds:Int, counterMode:Int)
+	Method Start:Int(cipher:TCipher, iv:Byte Ptr, key:Byte Ptr, keylen:Int, numRounds:Int, counterMode:ECTRCounterMode)
 		Local res:Int
 		Local res:Int
 		modePtr = bmx_crypto_ctr_start(cipher.index, iv, key, keylen, numRounds, counterMode, res)
 		modePtr = bmx_crypto_ctr_start(cipher.index, iv, key, keylen, numRounds, counterMode, res)
 		Return res
 		Return res

+ 1 - 1
ctrmode.mod/doc/tctrciphermode.bmx

@@ -32,7 +32,7 @@ Print "Encoded = " + TBase64.Encode(cbuf)
 Local buf:Byte[txt.length + 1]
 Local buf:Byte[txt.length + 1]
 
 
 cipherMode.Start(cipher, iv, key, 32, 14, ECTRCounterMode.LITTLE_ENDIAN)
 cipherMode.Start(cipher, iv, key, 32, 14, ECTRCounterMode.LITTLE_ENDIAN)
-cipherMode.Decrypt(cbuf, buf, txt.length)
+cipherMode.Decrypt(cbuf, buf, UInt(txt.length))
 cipherMode.Done()
 cipherMode.Done()
 
 
 Print "Decoded = " + String.FromUTF8String(buf)
 Print "Decoded = " + String.FromUTF8String(buf)

+ 1 - 1
ctrmode.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 11 - 1
descipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -34,4 +34,14 @@ Extern
 	Function bmx_crypto_des_keysize:Int(key:Int)
 	Function bmx_crypto_des_keysize:Int(key:Int)
 	Function bmx_crypto_3des_keysize:Int(key:Int)
 	Function bmx_crypto_3des_keysize:Int(key:Int)
 
 
+	Function des_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function des_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function des_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function des_done(skey:Byte Ptr)
+
+	Function des3_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function des3_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function des3_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function des3_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 65 - 3
descipher.mod/descipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -36,7 +36,7 @@ Import "common.bmx"
 New TDESCipherFactory(bmx_crypto_des_register())
 New TDESCipherFactory(bmx_crypto_des_register())
 New T3DESCipherFactory(bmx_crypto_3des_register())
 New T3DESCipherFactory(bmx_crypto_3des_register())
 
 
-Type TDESCipher Extends TCipher
+Type TDESCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_des_keysize(key)
 		Return bmx_crypto_des_keysize(key)
@@ -46,9 +46,40 @@ Type TDESCipher Extends TCipher
 		Return "DES"
 		Return "DES"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = des_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return des_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return des_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return des_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return des_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		des_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
-Type T3DESCipher Extends TCipher
+Type T3DESCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_3des_keysize(key)
 		Return bmx_crypto_3des_keysize(key)
@@ -58,6 +89,37 @@ Type T3DESCipher Extends TCipher
 		Return "3DES"
 		Return "3DES"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = des3_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return des3_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return des3_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return des3_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return des3_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		des3_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TDESCipherFactory Extends TCipherFactory
 Type TDESCipherFactory Extends TCipherFactory

+ 1 - 1
descipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 2 - 2
digest.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -22,7 +22,7 @@ SuperStrict
 Import Crypto.libtomcrypt
 Import Crypto.libtomcrypt
 Import pub.stdc
 Import pub.stdc
 Import brl.stream
 Import brl.stream
-Import brl.collections
+Import brl.linkedlist
 
 
 Import "source.bmx"
 Import "source.bmx"
 
 

+ 4 - 21
digest.mod/digest.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -50,16 +50,16 @@ Rem
 bbdoc: Returns a list of all currently registered digests.
 bbdoc: Returns a list of all currently registered digests.
 about: The returned digest names can be used with #GetMessageDigest to get a #TMessageDigest instance.
 about: The returned digest names can be used with #GetMessageDigest to get a #TMessageDigest instance.
 End Rem
 End Rem
-Function ListDigests:TArrayList<String>()
+Function ListDigests:TList()
 
 
-	Local list:TArrayLIst<String> = New TArrayList<String>()
+	Local list:TList = New TList
 
 
 	Local register:TDigestRegister=digest_registry
 	Local register:TDigestRegister=digest_registry
 
 
 	While register
 	While register
 		Local sp:String[] = register.ToString().Split(",")
 		Local sp:String[] = register.ToString().Split(",")
 		For Local digest:String = EachIn sp
 		For Local digest:String = EachIn sp
-			list.Add(digest.Trim())
+			list.AddLast(digest.Trim())
 		Next
 		Next
 		register = register._succ
 		register = register._succ
 	Wend
 	Wend
@@ -69,23 +69,6 @@ Function ListDigests:TArrayList<String>()
 	Return list
 	Return list
 End Function
 End Function
 
 
-Rem
-bbdoc: This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.
-End Rem
-Type TNoSuchAlgorithmException Extends TBlitzException
-
-	Field message:String
-
-	Method New(message:String)
-		Self.message = message
-	End Method
-
-	Method ToString:String() Override
-		Return message
-	End Method
-
-End Type
-
 Rem
 Rem
 bbdoc: An abstract base type for message digest implementations.
 bbdoc: An abstract base type for message digest implementations.
 End Rem
 End Rem

+ 1 - 1
digest.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
digest.mod/source.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
ecbmode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
ecbmode.mod/ecbmode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
ecbmode.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
f8mode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
f8mode.mod/f8mode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
f8mode.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
gcmauthmode.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 1 - 1
gcmauthmode.mod/gcmauthmode.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages

+ 6 - 1
ideacipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_idea_register:Int()
 	Function bmx_crypto_idea_register:Int()
 	Function bmx_crypto_idea_keysize:Int(key:Int)
 	Function bmx_crypto_idea_keysize:Int(key:Int)
 
 
+	Function idea_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function idea_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function idea_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function idea_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
ideacipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
ideacipher.mod/ideacipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TIdeaCipherFactory(bmx_crypto_idea_register())
 New TIdeaCipherFactory(bmx_crypto_idea_register())
 
 
-Type TIdeaCipher Extends TCipher
+Type TIdeaCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_idea_keysize(key)
 		Return bmx_crypto_idea_keysize(key)
@@ -45,6 +45,37 @@ Type TIdeaCipher Extends TCipher
 		Return "idea"
 		Return "idea"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = idea_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return idea_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return idea_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return idea_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return idea_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		idea_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TIdeaCipherFactory Extends TCipherFactory
 Type TIdeaCipherFactory Extends TCipherFactory

+ 6 - 1
kasumicipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_kasumi_register:Int()
 	Function bmx_crypto_kasumi_register:Int()
 	Function bmx_crypto_kasumi_keysize:Int(key:Int)
 	Function bmx_crypto_kasumi_keysize:Int(key:Int)
 
 
+	Function kasumi_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function kasumi_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function kasumi_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function kasumi_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
kasumicipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
kasumicipher.mod/kasumicipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TKasumiCipherFactory(bmx_crypto_kasumi_register())
 New TKasumiCipherFactory(bmx_crypto_kasumi_register())
 
 
-Type TKasumiCipher Extends TCipher
+Type TKasumiCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_kasumi_keysize(key)
 		Return bmx_crypto_kasumi_keysize(key)
@@ -45,6 +45,37 @@ Type TKasumiCipher Extends TCipher
 		Return "kasumi"
 		Return "kasumi"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = kasumi_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return kasumi_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return kasumi_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return kasumi_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return kasumi_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		kasumi_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TKasumiCipherFactory Extends TCipherFactory
 Type TKasumiCipherFactory Extends TCipherFactory

+ 6 - 1
khazadcipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_khazad_register:Int()
 	Function bmx_crypto_khazad_register:Int()
 	Function bmx_crypto_khazad_keysize:Int(key:Int)
 	Function bmx_crypto_khazad_keysize:Int(key:Int)
 
 
+	Function khazad_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function khazad_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function khazad_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function khazad_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
khazadcipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
khazadcipher.mod/khazadcipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TKhazadCipherFactory(bmx_crypto_khazad_register())
 New TKhazadCipherFactory(bmx_crypto_khazad_register())
 
 
-Type TKhazadCipher Extends TCipher
+Type TKhazadCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_khazad_keysize(key)
 		Return bmx_crypto_khazad_keysize(key)
@@ -45,6 +45,37 @@ Type TKhazadCipher Extends TCipher
 		Return "khazad"
 		Return "khazad"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = khazad_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return khazad_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return khazad_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return khazad_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return khazad_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		khazad_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TKhazadCipherFactory Extends TCipherFactory
 Type TKhazadCipherFactory Extends TCipherFactory

+ 6 - 1
kseedcipher.mod/common.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -32,4 +32,9 @@ Extern
 	Function bmx_crypto_kseed_register:Int()
 	Function bmx_crypto_kseed_register:Int()
 	Function bmx_crypto_kseed_keysize:Int(key:Int)
 	Function bmx_crypto_kseed_keysize:Int(key:Int)
 
 
+	Function kseed_setup:Int(key:Byte Ptr, keylen:Int, rounds:Int, skey:Byte Ptr)
+	Function kseed_ecb_encrypt:Int(pt:Byte Ptr, ct:Byte Ptr, skey:Byte Ptr)
+	Function kseed_ecb_decrypt:Int(ct:Byte Ptr, pt:Byte Ptr, skey:Byte Ptr)
+	Function kseed_done(skey:Byte Ptr)
+		
 End Extern
 End Extern

+ 1 - 1
kseedcipher.mod/glue.c

@@ -1,5 +1,5 @@
 /*
 /*
-  Copyright (C) 2019-2020 Bruce A Henderson
+  Copyright (C) 2019-2022 Bruce A Henderson
 
 
   This software is provided 'as-is', without any express or implied
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
   warranty.  In no event will the authors be held liable for any damages

+ 33 - 2
kseedcipher.mod/kseedcipher.bmx

@@ -1,5 +1,5 @@
 '
 '
-'  Copyright (C) 2019-2020 Bruce A Henderson
+'  Copyright (C) 2019-2022 Bruce A Henderson
 '
 '
 '  This software is provided 'as-is', without any express or implied
 '  This software is provided 'as-is', without any express or implied
 '  warranty.  In no event will the authors be held liable for any damages
 '  warranty.  In no event will the authors be held liable for any damages
@@ -35,7 +35,7 @@ Import "common.bmx"
 
 
 New TKSeedCipherFactory(bmx_crypto_kseed_register())
 New TKSeedCipherFactory(bmx_crypto_kseed_register())
 
 
-Type TKSeedCipher Extends TCipher
+Type TKSeedCipher Extends TBlockCipher
 
 
 	Method KeySize:Int(key:Int) Override
 	Method KeySize:Int(key:Int) Override
 		Return bmx_crypto_kseed_keysize(key)
 		Return bmx_crypto_kseed_keysize(key)
@@ -45,6 +45,37 @@ Type TKSeedCipher Extends TCipher
 		Return "kseed"
 		Return "kseed"
 	End Method
 	End Method
 
 
+	Method BlockSize:Int() Override
+		Return 8
+	End Method
+
+	Method Setup:Int(key:String, rounds:Int = 0) Override
+		Local s:Byte Ptr = key.ToUTF8String()
+		Local ret:Int = kseed_setup(s, Int(strlen_(s)), rounds, keyPtr)
+		MemFree(s)
+		Return ret
+	End Method
+
+	Method Setup:Int(key:Byte[], rounds:Int = 0) Override
+		Return kseed_setup(key, key.length, rounds, keyPtr)
+	End Method
+
+	Method Setup:Int(key:Byte Ptr, keylen:Int, rounds:Int = 0) Override
+		Return kseed_setup(key, keylen, rounds, keyPtr)
+	End Method
+
+	Method Encrypt:Int(pt:Byte Ptr, ct:Byte Ptr) Override
+		Return kseed_ecb_encrypt(pt, ct, keyPtr)
+	End Method
+
+	Method Decrypt:Int(ct:Byte Ptr, pt:Byte Ptr) Override
+		Return kseed_ecb_decrypt(ct, pt, keyPtr)		
+	End Method
+
+	Method Done() Override
+		kseed_done(keyPtr)
+	End Method
+
 End Type
 End Type
 
 
 Type TKSeedCipherFactory Extends TCipherFactory
 Type TKSeedCipherFactory Extends TCipherFactory

+ 1 - 1
libhydrogen.mod/libhydrogen.bmx

@@ -1,5 +1,5 @@
 '
 '
-' Copyright (c) 2019-2020 Bruce A Henderson
+' Copyright (c) 2019-2022 Bruce A Henderson
 '
 '
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' purpose with or without fee is hereby granted, provided that the above
 ' purpose with or without fee is hereby granted, provided that the above

+ 1 - 1
libhydrogen.mod/source.bmx

@@ -1,5 +1,5 @@
 '
 '
-' Copyright (c) 2019-2020 Bruce A Henderson
+' Copyright (c) 2019-2022 Bruce A Henderson
 '
 '
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' Permission to use, copy, modify, and/or distribute this software for any
 ' purpose with or without fee is hereby granted, provided that the above
 ' purpose with or without fee is hereby granted, provided that the above

+ 158 - 0
libtomcrypt.mod/common.bmx

@@ -0,0 +1,158 @@
+SuperStrict
+
+Rem
+bbdoc: Result OK
+End Rem
+Const CRYPT_OK:Int = 0
+
+Rem
+bbdoc: Generic Error
+End Rem
+Const CRYPT_ERROR:Int = 1
+
+Rem
+bbdoc: Not a failure but no operation was performed
+End Rem
+Const CRYPT_NOP:Int = 2
+
+Rem
+bbdoc: Invalid key size given
+End Rem
+Const CRYPT_INVALID_KEYSIZE:Int = 3
+
+Rem
+bbdoc: Invalid number of rounds
+End Rem
+Const CRYPT_INVALID_ROUNDS:Int = 4
+
+Rem
+bbdoc: Algorithm failed test vectors
+End Rem
+Const CRYPT_FAIL_TESTVECTOR:Int = 5
+
+Rem
+bbdoc: Not enough space for output
+End Rem
+Const CRYPT_BUFFER_OVERFLOW:Int = 6
+
+Rem
+bbdoc: Invalid input packet given
+End Rem
+Const CRYPT_INVALID_PACKET:Int = 7
+
+Rem
+bbdoc: Invalid number of bits for a PRNG
+End Rem
+Const CRYPT_INVALID_PRNGSIZE:Int = 8
+
+Rem
+bbdoc: Could not read enough from PRNG
+End Rem
+Const CRYPT_ERROR_READPRNG:Int = 9
+
+Rem
+bbdoc: Invalid cipher specified
+End Rem
+Const CRYPT_INVALID_CIPHER:Int = 10
+
+Rem
+bbdoc: Invalid hash specified
+End Rem
+Const CRYPT_INVALID_HASH:Int = 11
+
+Rem
+bbdoc: Invalid PRNG specified
+End Rem
+Const CRYPT_INVALID_PRNG:Int = 12
+
+Rem
+bbdoc: Out of memory
+End Rem
+Const CRYPT_MEM:Int = 13
+
+Rem
+bbdoc: Not equivalent types of PK keys
+End Rem
+Const CRYPT_PK_TYPE_MISMATCH:Int = 14
+
+Rem
+bbdoc: Requires a private PK key
+End Rem
+Const CRYPT_PK_NOT_PRIVATE:Int = 15
+
+Rem
+bbdoc: Generic invalid argument
+End Rem
+Const CRYPT_INVALID_ARG:Int = 16
+
+Rem
+bbdoc: File Not Found
+End Rem
+Const CRYPT_FILE_NOTFOUND:Int = 17
+
+Rem
+bbdoc: Invalid type of PK key
+End Rem
+Const CRYPT_PK_INVALID_TYPE:Int = 18
+
+Rem
+bbdoc: An overflow of a value was detected/prevented
+End Rem
+Const CRYPT_OVERFLOW:Int = 19
+
+Rem
+bbdoc: An error occurred while en- or decoding ASN.1 data
+End Rem
+Const CRYPT_PK_ASN1_ERROR:Int = 20
+
+Rem
+bbdoc: The input was longer than expected.
+End Rem
+Const CRYPT_INPUT_TOO_LONG:Int = 21
+
+
+Rem
+bbdoc: Invalid size input for PK parameters
+End Rem
+Const CRYPT_PK_INVALID_SIZE:Int = 22
+
+Rem
+bbdoc: Invalid size of prime requested
+End Rem
+Const CRYPT_INVALID_PRIME_SIZE:Int = 23
+
+Rem
+bbdoc: Invalid padding on input
+End Rem
+Const CRYPT_PK_INVALID_PADDING:Int = 24
+
+Rem
+bbdoc: Hash applied to too many bits
+End Rem
+Const CRYPT_HASH_OVERFLOW:Int = 25
+
+
+Rem
+bbdoc: This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.
+End Rem
+Type TNoSuchAlgorithmException Extends TBlitzException
+
+	Field message:String
+
+	Method New(message:String)
+		Self.message = message
+	End Method
+
+	Method ToString:String() Override
+		Return message
+	End Method
+
+End Type
+
+
+Const LTC_PAD_PKCS7:UInt        = $0000:UInt
+Const LTC_PAD_ANSI_X923:UInt    = $2000:UInt
+Const LTC_PAD_SSH:UInt          = $3000:UInt
+Const LTC_PAD_ONE_AND_ZERO:UInt = $8000:UInt
+Const LTC_PAD_ZERO:UInt         = $9000:UInt
+Const LTC_PAD_ZERO_ALWAYS:UInt  = $A000:UInt

+ 12 - 0
libtomcrypt.mod/libtomcrypt.bmx

@@ -3,8 +3,20 @@ SuperStrict
 
 
 Module Crypto.libtomcrypt
 Module Crypto.libtomcrypt
 
 
+ModuleInfo "Version: 1.01"
+ModuleInfo "Author: Frank Denis."
+ModuleInfo "License: ISC"
+ModuleInfo "Credit: Adapted for BlitzMax by Bruce A Henderson"
+
+ModuleInfo "History: 1.01"
+ModuleInfo "History: Updated to libtomcrypt 1.18.2.3474ca3"
+ModuleInfo "History: 1.00"
+ModuleInfo "History: Initial Release."
+
 ModuleInfo "CC_OPTS: -DLTC_NO_TEST -DLTC_NO_FILE"
 ModuleInfo "CC_OPTS: -DLTC_NO_TEST -DLTC_NO_FILE"
 
 
+Import "common.bmx"
+
 Import "libtomcrypt/src/headers/*.h"
 Import "libtomcrypt/src/headers/*.h"
 
 
 Import "libtomcrypt/src/misc/base16/base16_decode.c"
 Import "libtomcrypt/src/misc/base16/base16_decode.c"

+ 26 - 29
libtomcrypt.mod/libtomcrypt/LICENSE

@@ -1,29 +1,26 @@
-LibTomCrypt is licensed under DUAL licensing terms.
-
-Choose and use the license of your needs.
-
-[LICENSE #1]
-
-LibTomCrypt is public domain.  As should all quality software be.
-
-Tom St Denis
-
-[/LICENSE #1]
-
-[LICENSE #2]
-
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-                    Version 2, December 2004
-
- Copyright (C) 2004 Sam Hocevar <[email protected]>
-
- Everyone is permitted to copy and distribute verbatim or modified
- copies of this license document, and changing it is allowed as long
- as the name is changed.
-
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. You just DO WHAT THE FUCK YOU WANT TO. 
-
-[/LICENSE #2]
+                          The LibTom license
+
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>

+ 7 - 17
libtomcrypt.mod/libtomcrypt/src/ciphers/aes/aes.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /* AES implementation by Tom St Denis
 /* AES implementation by Tom St Denis
  *
  *
@@ -86,7 +80,7 @@ const struct ltc_cipher_descriptor aes_enc_desc =
 
 
 #endif
 #endif
 
 
-#define __LTC_AES_TAB_C__
+#define LTC_AES_TAB_C
 #include "aes_tab.c"
 #include "aes_tab.c"
 
 
 static ulong32 setup_mix(ulong32 temp)
 static ulong32 setup_mix(ulong32 temp)
@@ -281,7 +275,7 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -449,7 +443,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _rijndael_ecb_encrypt(pt, ct, skey);
+   int err = s_rijndael_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
    burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
    return err;
    return err;
 }
 }
@@ -465,7 +459,7 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -634,7 +628,7 @@ int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *ske
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _rijndael_ecb_decrypt(ct, pt, skey);
+   int err = s_rijndael_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
    burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
    return err;
    return err;
 }
 }
@@ -748,7 +742,3 @@ int ECB_KS(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 4 - 14
libtomcrypt.mod/libtomcrypt/src/ciphers/aes/aes_tab.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 /* The precomputed tables for AES */
 /* The precomputed tables for AES */
 /*
 /*
 Te0[x] = S [x].[02, 01, 01, 03];
 Te0[x] = S [x].[02, 01, 01, 03];
@@ -21,7 +15,7 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
 Td4[x] = Si[x].[01, 01, 01, 01];
 Td4[x] = Si[x].[01, 01, 01, 01];
 */
 */
 
 
-#ifdef __LTC_AES_TAB_C__
+#ifdef LTC_AES_TAB_C
 
 
 /**
 /**
   @file aes_tab.c
   @file aes_tab.c
@@ -1025,8 +1019,4 @@ static const ulong32 rcon[] = {
 };
 };
 #endif
 #endif
 
 
-#endif /* __LTC_AES_TAB_C__ */
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */
+#endif /* LTC_AES_TAB_C */

+ 14 - 14
libtomcrypt.mod/libtomcrypt/src/ciphers/anubis.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file anubis.c
   @file anubis.c
@@ -882,7 +876,7 @@ static const ulong32 rc[] = {
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+static int s_anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 #else
 int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #endif
 #endif
@@ -1019,7 +1013,7 @@ int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
 int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
 {
   int err;
   int err;
-  err = _anubis_setup(key, keylen, num_rounds, skey);
+  err = s_anubis_setup(key, keylen, num_rounds, skey);
   burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5));
   burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5));
   return err;
   return err;
 }
 }
@@ -1131,6 +1125,11 @@ int anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetr
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
+
+   if (skey->anubis.R < 12 || skey->anubis.R > 18) {
+       return CRYPT_INVALID_ROUNDS;
+   }
+
    anubis_crypt(pt, ct, skey->anubis.roundKeyEnc, skey->anubis.R);
    anubis_crypt(pt, ct, skey->anubis.roundKeyEnc, skey->anubis.R);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
@@ -1147,6 +1146,11 @@ int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetr
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
+
+   if (skey->anubis.R < 12 || skey->anubis.R > 18) {
+       return CRYPT_INVALID_ROUNDS;
+   }
+
    anubis_crypt(ct, pt, skey->anubis.roundKeyDec, skey->anubis.R);
    anubis_crypt(ct, pt, skey->anubis.roundKeyDec, skey->anubis.R);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
@@ -1544,7 +1548,3 @@ int anubis_keysize(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 154 - 91
libtomcrypt.mod/libtomcrypt/src/ciphers/blowfish.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 /**
 /**
   @file blowfish.c
   @file blowfish.c
   Implementation of the Blowfish block cipher, Tom St Denis
   Implementation of the Blowfish block cipher, Tom St Denis
@@ -295,73 +289,128 @@ static const ulong32 ORIG_S[4][256] = {
         0xB74E6132UL, 0xCE77E25BUL, 0x578FDFE3UL, 0x3AC372E6UL  }
         0xB74E6132UL, 0xCE77E25BUL, 0x578FDFE3UL, 0x3AC372E6UL  }
 };
 };
 
 
+#ifndef __GNUC__
+#define F(x) ((S1[LTC_BYTE(x,3)] + S2[LTC_BYTE(x,2)]) ^ S3[LTC_BYTE(x,1)]) + S4[LTC_BYTE(x,0)]
+#else
+#define F(x) ((skey->blowfish.S[0][LTC_BYTE(x,3)] + skey->blowfish.S[1][LTC_BYTE(x,2)]) ^ skey->blowfish.S[2][LTC_BYTE(x,1)]) + skey->blowfish.S[3][LTC_BYTE(x,0)]
+#endif
+
+static void s_blowfish_encipher(ulong32 *L, ulong32 *R, const symmetric_key *skey)
+{
+   int rounds;
+
+   ulong32 l, r;
+#ifndef __GNUC__
+   const ulong32 *S1, *S2, *S3, *S4;
+
+   S1 = skey->blowfish.S[0];
+   S2 = skey->blowfish.S[1];
+   S3 = skey->blowfish.S[2];
+   S4 = skey->blowfish.S[3];
+#endif
+
+   l = *L;
+   r = *R;
+
+   /* do 16 rounds */
+   for (rounds = 0; rounds < 16; ) {
+      l ^= skey->blowfish.K[rounds++];  r ^= F(l);
+      r ^= skey->blowfish.K[rounds++];  l ^= F(r);
+      l ^= skey->blowfish.K[rounds++];  r ^= F(l);
+      r ^= skey->blowfish.K[rounds++];  l ^= F(r);
+   }
+
+   /* last keying */
+   l ^= skey->blowfish.K[16];
+   r ^= skey->blowfish.K[17];
+
+   *L = r;
+   *R = l;
+}
+
+void blowfish_enc(ulong32 *data, unsigned long blocks, const symmetric_key *skey)
+{
+   unsigned long i;
+   ulong32 *d = data;
+
+   for (i = 0; i < blocks; ++i) {
+      s_blowfish_encipher(d, d + 1, skey);
+      d += 2;
+   }
+}
+
+static ulong32 s_blowfish_stream2word(const unsigned char *d, int dlen, int *cur)
+{
+   unsigned int z;
+   int y = *cur;
+   ulong32 ret = 0;
+
+   for (z = 0; z < 4; z++) {
+       ret = (ret << 8) | ((ulong32)d[y++] & 255);
+       if (y == dlen) {
+          y = 0;
+       }
+   }
+
+   *cur = y;
+   return ret;
+}
+
  /**
  /**
-    Initialize the Blowfish block cipher
+    Expand the Blowfish internal state
     @param key The symmetric key you wish to pass
     @param key The symmetric key you wish to pass
     @param keylen The key length in bytes
     @param keylen The key length in bytes
+    @param data The additional data you wish to pass (can be NULL)
+    @param datalen The additional data length in bytes
     @param num_rounds The number of rounds desired (0 for default)
     @param num_rounds The number of rounds desired (0 for default)
     @param skey The key in as scheduled by this function.
     @param skey The key in as scheduled by this function.
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
-int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
-                   symmetric_key *skey)
+int blowfish_expand(const unsigned char *key, int keylen,
+                    const unsigned char *data, int datalen,
+                    symmetric_key *skey)
 {
 {
-   ulong32 x, y, z, A;
-   unsigned char B[8];
+   ulong32 x, y, A, B[2];
+   int i;
 
 
    LTC_ARGCHK(key != NULL);
    LTC_ARGCHK(key != NULL);
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
 
 
-   /* check key length */
-   if (keylen < 8 || keylen > 56) {
-      return CRYPT_INVALID_KEYSIZE;
-   }
-
-   /* check rounds */
-   if (num_rounds != 0 && num_rounds != 16) {
-      return CRYPT_INVALID_ROUNDS;
-   }
-
    /* load in key bytes (Supplied by David Hopwood) */
    /* load in key bytes (Supplied by David Hopwood) */
-   for (x = y = 0; x < 18; x++) {
-       A = 0;
-       for (z = 0; z < 4; z++) {
-           A = (A << 8) | ((ulong32)key[y++] & 255);
-           if (y == (ulong32)keylen) {
-              y = 0;
-           }
-       }
-       skey->blowfish.K[x] = ORIG_P[x] ^ A;
-   }
-
-   /* copy sboxes */
-   for (x = 0; x < 4; x++) {
-       for (y = 0; y < 256; y++) {
-           skey->blowfish.S[x][y] = ORIG_S[x][y];
-       }
+   i = 0;
+   for (x = 0; x < 18; x++) {
+       A = s_blowfish_stream2word(key, keylen, &i);
+       skey->blowfish.K[x] ^= A;
    }
    }
 
 
-   /* encrypt K array */
-   for (x = 0; x < 8; x++) {
-       B[x] = 0;
-   }
 
 
+   i = 0;
+   B[0] = 0;
+   B[1] = 0;
    for (x = 0; x < 18; x += 2) {
    for (x = 0; x < 18; x += 2) {
-       /* encrypt it */
-       blowfish_ecb_encrypt(B, B, skey);
-       /* copy it */
-       LOAD32H(skey->blowfish.K[x], &B[0]);
-       LOAD32H(skey->blowfish.K[x+1], &B[4]);
+      if (data != NULL) {
+         B[0] ^= s_blowfish_stream2word(data, datalen, &i);
+         B[1] ^= s_blowfish_stream2word(data, datalen, &i);
+      }
+      /* encrypt it */
+      s_blowfish_encipher(&B[0], &B[1], skey);
+      /* copy it */
+      skey->blowfish.K[x] = B[0];
+      skey->blowfish.K[x+1] = B[1];
    }
    }
 
 
    /* encrypt S array */
    /* encrypt S array */
    for (x = 0; x < 4; x++) {
    for (x = 0; x < 4; x++) {
        for (y = 0; y < 256; y += 2) {
        for (y = 0; y < 256; y += 2) {
+          if (data != NULL) {
+             B[0] ^= s_blowfish_stream2word(data, datalen, &i);
+             B[1] ^= s_blowfish_stream2word(data, datalen, &i);
+          }
           /* encrypt it */
           /* encrypt it */
-          blowfish_ecb_encrypt(B, B, skey);
+          s_blowfish_encipher(&B[0], &B[1], skey);
           /* copy it */
           /* copy it */
-          LOAD32H(skey->blowfish.S[x][y], &B[0]);
-          LOAD32H(skey->blowfish.S[x][y+1], &B[4]);
+          skey->blowfish.S[x][y] = B[0];
+          skey->blowfish.S[x][y+1] = B[1];
        }
        }
    }
    }
 
 
@@ -372,11 +421,48 @@ int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-#ifndef __GNUC__
-#define F(x) ((S1[LTC_BYTE(x,3)] + S2[LTC_BYTE(x,2)]) ^ S3[LTC_BYTE(x,1)]) + S4[LTC_BYTE(x,0)]
-#else
-#define F(x) ((skey->blowfish.S[0][LTC_BYTE(x,3)] + skey->blowfish.S[1][LTC_BYTE(x,2)]) ^ skey->blowfish.S[2][LTC_BYTE(x,1)]) + skey->blowfish.S[3][LTC_BYTE(x,0)]
-#endif
+/**
+   Initialize the Blowfish block cipher
+   @param key The symmetric key you wish to pass
+   @param keylen The key length in bytes
+   @param num_rounds The number of rounds desired (0 for default)
+   @param skey The key in as scheduled by this function.
+   @return CRYPT_OK if successful
+*/
+int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
+                  symmetric_key *skey)
+{
+   /* check key length */
+   if (keylen < 8 || keylen > 56) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+   /* check rounds */
+   if (num_rounds != 0 && num_rounds != 16) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
+   return blowfish_setup_with_data(key, keylen, NULL, 0, skey);
+}
+
+/**
+   Alternative initialize of the Blowfish block cipher
+   @param key The symmetric key you wish to pass
+   @param keylen The key length in bytes
+   @param data The additional data you wish to pass (can be NULL)
+   @param datalen The additional data length in bytes
+   @param num_rounds The number of rounds desired (0 for default)
+   @param skey The key in as scheduled by this function.
+   @return CRYPT_OK if successful
+*/
+
+int blowfish_setup_with_data(const unsigned char *key, int keylen,
+                             const unsigned char *data, int datalen,
+                             symmetric_key *skey)
+{
+   XMEMCPY(skey->blowfish.K, ORIG_P, sizeof(ORIG_P));
+   XMEMCPY(skey->blowfish.S, ORIG_S, sizeof(ORIG_S));
+   return blowfish_expand(key, keylen, data, datalen, skey);
+}
 
 
 /**
 /**
   Encrypts a block of text with Blowfish
   Encrypts a block of text with Blowfish
@@ -386,47 +472,26 @@ int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
 {
 {
    ulong32 L, R;
    ulong32 L, R;
-   int r;
-#ifndef __GNUC__
-   const ulong32 *S1, *S2, *S3, *S4;
-#endif
 
 
-    LTC_ARGCHK(pt   != NULL);
-    LTC_ARGCHK(ct   != NULL);
-    LTC_ARGCHK(skey != NULL);
-
-#ifndef __GNUC__
-    S1 = skey->blowfish.S[0];
-    S2 = skey->blowfish.S[1];
-    S3 = skey->blowfish.S[2];
-    S4 = skey->blowfish.S[3];
-#endif
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
 
    /* load it */
    /* load it */
    LOAD32H(L, &pt[0]);
    LOAD32H(L, &pt[0]);
    LOAD32H(R, &pt[4]);
    LOAD32H(R, &pt[4]);
 
 
-   /* do 16 rounds */
-   for (r = 0; r < 16; ) {
-      L ^= skey->blowfish.K[r++];  R ^= F(L);
-      R ^= skey->blowfish.K[r++];  L ^= F(R);
-      L ^= skey->blowfish.K[r++];  R ^= F(L);
-      R ^= skey->blowfish.K[r++];  L ^= F(R);
-   }
-
-   /* last keying */
-   R ^= skey->blowfish.K[17];
-   L ^= skey->blowfish.K[16];
+   s_blowfish_encipher(&L, &R, skey);
 
 
    /* store */
    /* store */
-   STORE32H(R, &ct[0]);
-   STORE32H(L, &ct[4]);
+   STORE32H(L, &ct[0]);
+   STORE32H(R, &ct[4]);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
@@ -434,7 +499,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-    int err = _blowfish_ecb_encrypt(pt, ct, skey);
+    int err = s_blowfish_ecb_encrypt(pt, ct, skey);
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
     return err;
     return err;
 }
 }
@@ -448,7 +513,7 @@ int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -495,7 +560,7 @@ int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-    int err = _blowfish_ecb_decrypt(ct, pt, skey);
+    int err = s_blowfish_ecb_decrypt(ct, pt, skey);
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
     return err;
     return err;
 }
 }
@@ -557,6 +622,8 @@ int blowfish_test(void)
       for (y = 0; y < 1000; y++) blowfish_ecb_decrypt(tmp[0], tmp[0], &key);
       for (y = 0; y < 1000; y++) blowfish_ecb_decrypt(tmp[0], tmp[0], &key);
       for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
       for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
    }
    }
+
+
    return CRYPT_OK;
    return CRYPT_OK;
  #endif
  #endif
 }
 }
@@ -589,7 +656,3 @@ int blowfish_keysize(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 6 - 12
libtomcrypt.mod/libtomcrypt/src/ciphers/camellia.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file camellia.c
   @file camellia.c
@@ -627,6 +621,9 @@ int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
 
 
 int camellia_test(void)
 int camellia_test(void)
 {
 {
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
    static const struct {
    static const struct {
       int keylen;
       int keylen;
       unsigned char key[32], pt[16], ct[16];
       unsigned char key[32], pt[16], ct[16];
@@ -703,6 +700,7 @@ int camellia_test(void)
       }
       }
    }
    }
    return CRYPT_OK;
    return CRYPT_OK;
+#endif
 }
 }
 
 
 void camellia_done(symmetric_key *skey)
 void camellia_done(symmetric_key *skey)
@@ -720,7 +718,3 @@ int camellia_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 11 - 27
libtomcrypt.mod/libtomcrypt/src/ciphers/cast5.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
  /**
  /**
    @file cast5.c
    @file cast5.c
@@ -404,7 +398,7 @@ static const ulong32 S8[256] = {
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+static int s_cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 #else
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #endif
 #endif
@@ -491,19 +485,13 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
 {
    int z;
    int z;
-   z = _cast5_setup(key, keylen, num_rounds, skey);
+   z = s_cast5_setup(key, keylen, num_rounds, skey);
    burn_stack(sizeof(ulong32)*8 + 16 + sizeof(int)*2);
    burn_stack(sizeof(ulong32)*8 + 16 + sizeof(int)*2);
    return z;
    return z;
 }
 }
 #endif
 #endif
 
 
-#ifdef _MSC_VER
-   #define INLINE __inline
-#else
-   #define INLINE
-#endif
-
-INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
+LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
 {
 {
    ulong32 I;
    ulong32 I;
    I = (Km + R);
    I = (Km + R);
@@ -511,7 +499,7 @@ INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
    return ((S1[LTC_BYTE(I, 3)] ^ S2[LTC_BYTE(I,2)]) - S3[LTC_BYTE(I,1)]) + S4[LTC_BYTE(I,0)];
    return ((S1[LTC_BYTE(I, 3)] ^ S2[LTC_BYTE(I,2)]) - S3[LTC_BYTE(I,1)]) + S4[LTC_BYTE(I,0)];
 }
 }
 
 
-INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
+LTC_INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
 {
 {
    ulong32 I;
    ulong32 I;
    I = (Km ^ R);
    I = (Km ^ R);
@@ -519,7 +507,7 @@ INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
    return ((S1[LTC_BYTE(I, 3)] - S2[LTC_BYTE(I,2)]) + S3[LTC_BYTE(I,1)]) ^ S4[LTC_BYTE(I,0)];
    return ((S1[LTC_BYTE(I, 3)] - S2[LTC_BYTE(I,2)]) + S3[LTC_BYTE(I,1)]) ^ S4[LTC_BYTE(I,0)];
 }
 }
 
 
-INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
+LTC_INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
 {
 {
    ulong32 I;
    ulong32 I;
    I = (Km - R);
    I = (Km - R);
@@ -534,7 +522,7 @@ INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
   @param skey The key as scheduled
   @param skey The key as scheduled
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -574,7 +562,7 @@ int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetri
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err =_cast5_ecb_encrypt(pt,ct,skey);
+   int err = s_cast5_ecb_encrypt(pt,ct,skey);
    burn_stack(sizeof(ulong32)*3);
    burn_stack(sizeof(ulong32)*3);
    return err;
    return err;
 }
 }
@@ -587,7 +575,7 @@ int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetri
   @param skey The key as scheduled
   @param skey The key as scheduled
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -627,7 +615,7 @@ int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetri
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _cast5_ecb_decrypt(ct,pt,skey);
+   int err = s_cast5_ecb_decrypt(ct,pt,skey);
    burn_stack(sizeof(ulong32)*3);
    burn_stack(sizeof(ulong32)*3);
    return err;
    return err;
 }
 }
@@ -715,7 +703,3 @@ int cast5_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 296 - 290
libtomcrypt.mod/libtomcrypt/src/ciphers/des.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 #include "tomcrypt_private.h"
 #include "tomcrypt_private.h"
 
 
 /**
 /**
@@ -1299,7 +1293,7 @@ static const ulong64 des_fp[8][256] = {
 static void cookey(const ulong32 *raw1, ulong32 *keyout);
 static void cookey(const ulong32 *raw1, ulong32 *keyout);
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static void _deskey(const unsigned char *key, short edf, ulong32 *keyout)
+static void s_deskey(const unsigned char *key, short edf, ulong32 *keyout)
 #else
 #else
 static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 #endif
 #endif
@@ -1353,13 +1347,13 @@ static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 {
 {
-   _deskey(key, edf, keyout);
+   s_deskey(key, edf, keyout);
    burn_stack(sizeof(int)*5 + sizeof(ulong32)*32 + sizeof(unsigned char)*112);
    burn_stack(sizeof(int)*5 + sizeof(ulong32)*32 + sizeof(unsigned char)*112);
 }
 }
 #endif
 #endif
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static void _cookey(const ulong32 *raw1, ulong32 *keyout)
+static void s_cookey(const ulong32 *raw1, ulong32 *keyout)
 #else
 #else
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 #endif
 #endif
@@ -1389,7 +1383,7 @@ static void cookey(const ulong32 *raw1, ulong32 *keyout)
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 {
 {
-   _cookey(raw1, keyout);
+   s_cookey(raw1, keyout);
    burn_stack(sizeof(ulong32 *) * 2 + sizeof(ulong32)*32 + sizeof(int));
    burn_stack(sizeof(ulong32 *) * 2 + sizeof(ulong32)*32 + sizeof(int));
 }
 }
 #endif
 #endif
@@ -1397,7 +1391,7 @@ static void cookey(const ulong32 *raw1, ulong32 *keyout)
 #ifndef LTC_CLEAN_STACK
 #ifndef LTC_CLEAN_STACK
 static void desfunc(ulong32 *block, const ulong32 *keys)
 static void desfunc(ulong32 *block, const ulong32 *keys)
 #else
 #else
-static void _desfunc(ulong32 *block, const ulong32 *keys)
+static void s_desfunc(ulong32 *block, const ulong32 *keys)
 #endif
 #endif
 {
 {
     ulong32 work, right, leftt;
     ulong32 work, right, leftt;
@@ -1511,7 +1505,7 @@ static void _desfunc(ulong32 *block, const ulong32 *keys)
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 static void desfunc(ulong32 *block, const ulong32 *keys)
 static void desfunc(ulong32 *block, const ulong32 *keys)
 {
 {
-   _desfunc(block, keys);
+   s_desfunc(block, keys);
    burn_stack(sizeof(ulong32) * 4 + sizeof(int));
    burn_stack(sizeof(ulong32) * 4 + sizeof(int));
 }
 }
 #endif
 #endif
@@ -1683,243 +1677,208 @@ int des_test(void)
  #ifndef LTC_TEST
  #ifndef LTC_TEST
     return CRYPT_NOP;
     return CRYPT_NOP;
  #else
  #else
-    int err;
     static const struct des_test_case {
     static const struct des_test_case {
-        int num, mode; /* mode 1 = encrypt */
         unsigned char key[8], txt[8], out[8];
         unsigned char key[8], txt[8], out[8];
     } cases[] = {
     } cases[] = {
-        { 1, 1,     { 0x10, 0x31, 0x6E, 0x02, 0x8C, 0x8F, 0x3B, 0x4A },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x82, 0xDC, 0xBA, 0xFB, 0xDE, 0xAB, 0x66, 0x02 } },
-        { 2, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x95, 0xF8, 0xA5, 0xE5, 0xDD, 0x31, 0xD9, 0x00 },
-                    { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 3, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0xDD, 0x7F, 0x12, 0x1C, 0xA5, 0x01, 0x56, 0x19 },
-                    { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 4, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x2E, 0x86, 0x53, 0x10, 0x4F, 0x38, 0x34, 0xEA },
-                    { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 5, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x4B, 0xD3, 0x88, 0xFF, 0x6C, 0xD8, 0x1D, 0x4F },
-                    { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 6, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x20, 0xB9, 0xE7, 0x67, 0xB2, 0xFB, 0x14, 0x56 },
-                    { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 7, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x55, 0x57, 0x93, 0x80, 0xD7, 0x71, 0x38, 0xEF },
-                    { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 8, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x6C, 0xC5, 0xDE, 0xFA, 0xAF, 0x04, 0x51, 0x2F },
-                    { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 9, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x0D, 0x9F, 0x27, 0x9B, 0xA5, 0xD8, 0x72, 0x60 },
-                    { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        {10, 1,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0xD9, 0x03, 0x1B, 0x02, 0x71, 0xBD, 0x5A, 0x0A },
-                    { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-
-        { 1, 0,     { 0x10, 0x31, 0x6E, 0x02, 0x8C, 0x8F, 0x3B, 0x4A },
-                    { 0x82, 0xDC, 0xBA, 0xFB, 0xDE, 0xAB, 0x66, 0x02 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
-        { 2, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x95, 0xF8, 0xA5, 0xE5, 0xDD, 0x31, 0xD9, 0x00 } },
-        { 3, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xDD, 0x7F, 0x12, 0x1C, 0xA5, 0x01, 0x56, 0x19 } },
-        { 4, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x2E, 0x86, 0x53, 0x10, 0x4F, 0x38, 0x34, 0xEA } },
-        { 5, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x4B, 0xD3, 0x88, 0xFF, 0x6C, 0xD8, 0x1D, 0x4F } },
-        { 6, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x20, 0xB9, 0xE7, 0x67, 0xB2, 0xFB, 0x14, 0x56 } },
-        { 7, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x55, 0x57, 0x93, 0x80, 0xD7, 0x71, 0x38, 0xEF } },
-        { 8, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x6C, 0xC5, 0xDE, 0xFA, 0xAF, 0x04, 0x51, 0x2F } },
-        { 9, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x0D, 0x9F, 0x27, 0x9B, 0xA5, 0xD8, 0x72, 0x60 } },
-        {10, 0,     { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xD9, 0x03, 0x1B, 0x02, 0x71, 0xBD, 0x5A, 0x0A } },
-
-#ifdef LTC_TEST_EXT
-        { 0+11, 0,  { 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x95, 0xA8, 0xD7, 0x28, 0x13, 0xDA, 0xA9, 0x4D } },
-        { 1+11, 0,  { 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x0E, 0xEC, 0x14, 0x87, 0xDD, 0x8C, 0x26, 0xD5 } },
-        { 2+11, 0,  { 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x7A, 0xD1, 0x6F, 0xFB, 0x79, 0xC4, 0x59, 0x26 } },
-        { 3+11, 0,  { 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xD3, 0x74, 0x62, 0x94, 0xCA, 0x6A, 0x6C, 0xF3 } },
-        { 4+11, 0,  { 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x80, 0x9F, 0x5F, 0x87, 0x3C, 0x1F, 0xD7, 0x61 } },
-        { 5+11, 0,  { 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xC0, 0x2F, 0xAF, 0xFE, 0xC9, 0x89, 0xD1, 0xFC } },
-        { 6+11, 0,  { 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x46, 0x15, 0xAA, 0x1D, 0x33, 0xE7, 0x2F, 0x10 } },
-        { 7+11, 0,  { 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x20, 0x55, 0x12, 0x33, 0x50, 0xC0, 0x08, 0x58 } },
-        { 8+11, 0,  { 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xDF, 0x3B, 0x99, 0xD6, 0x57, 0x73, 0x97, 0xC8 } },
-        { 9+11, 0,  { 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x31, 0xFE, 0x17, 0x36, 0x9B, 0x52, 0x88, 0xC9 } },
-        {10+11, 0,  { 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xDF, 0xDD, 0x3C, 0xC6, 0x4D, 0xAE, 0x16, 0x42 } },
-        {11+11, 0,  { 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x17, 0x8C, 0x83, 0xCE, 0x2B, 0x39, 0x9D, 0x94 } },
-        {12+11, 0,  { 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x50, 0xF6, 0x36, 0x32, 0x4A, 0x9B, 0x7F, 0x80 } },
-        {13+11, 0,  { 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xA8, 0x46, 0x8E, 0xE3, 0xBC, 0x18, 0xF0, 0x6D } },
-        {14+11, 0,  { 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xA2, 0xDC, 0x9E, 0x92, 0xFD, 0x3C, 0xDE, 0x92 } },
-        {15+11, 0,  { 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xCA, 0xC0, 0x9F, 0x79, 0x7D, 0x03, 0x12, 0x87 } },
-        {16+11, 0,  { 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x90, 0xBA, 0x68, 0x0B, 0x22, 0xAE, 0xB5, 0x25 } },
-        {17+11, 0,  { 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xCE, 0x7A, 0x24, 0xF3, 0x50, 0xE2, 0x80, 0xB6 } },
-        {18+11, 0,  { 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x88, 0x2B, 0xFF, 0x0A, 0xA0, 0x1A, 0x0B, 0x87 } },
-        {19+11, 0,  { 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x25, 0x61, 0x02, 0x88, 0x92, 0x45, 0x11, 0xC2 } },
-        {20+11, 0,  { 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xC7, 0x15, 0x16, 0xC2, 0x9C, 0x75, 0xD1, 0x70 } },
-        {21+11, 0,  { 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x51, 0x99, 0xC2, 0x9A, 0x52, 0xC9, 0xF0, 0x59 } },
-        {22+11, 0,  { 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xC2, 0x2F, 0x0A, 0x29, 0x4A, 0x71, 0xF2, 0x9F } },
-        {23+11, 0,  { 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xEE, 0x37, 0x14, 0x83, 0x71, 0x4C, 0x02, 0xEA } },
-        {24+11, 0,  { 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xA8, 0x1F, 0xBD, 0x44, 0x8F, 0x9E, 0x52, 0x2F } },
-        {25+11, 0,  { 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x4F, 0x64, 0x4C, 0x92, 0xE1, 0x92, 0xDF, 0xED } },
-        {26+11, 0,  { 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x1A, 0xFA, 0x9A, 0x66, 0xA6, 0xDF, 0x92, 0xAE } },
-        {27+11, 0,  { 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xB3, 0xC1, 0xCC, 0x71, 0x5C, 0xB8, 0x79, 0xD8 } },
-        {28+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x19, 0xD0, 0x32, 0xE6, 0x4A, 0xB0, 0xBD, 0x8B } },
-        {29+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x3C, 0xFA, 0xA7, 0xA7, 0xDC, 0x87, 0x20, 0xDC } },
-        {30+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xB7, 0x26, 0x5F, 0x7F, 0x44, 0x7A, 0xC6, 0xF3 } },
-        {31+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x9D, 0xB7, 0x3B, 0x3C, 0x0D, 0x16, 0x3F, 0x54 } },
-        {32+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x81, 0x81, 0xB6, 0x5B, 0xAB, 0xF4, 0xA9, 0x75 } },
-        {33+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x93, 0xC9, 0xB6, 0x40, 0x42, 0xEA, 0xA2, 0x40 } },
-        {34+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x55, 0x70, 0x53, 0x08, 0x29, 0x70, 0x55, 0x92 } },
-        {35+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x86, 0x38, 0x80, 0x9E, 0x87, 0x87, 0x87, 0xA0 } },
-        {36+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x41, 0xB9, 0xA7, 0x9A, 0xF7, 0x9A, 0xC2, 0x08 } },
-        {37+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x7A, 0x9B, 0xE4, 0x2F, 0x20, 0x09, 0xA8, 0x92 } },
-        {38+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x29, 0x03, 0x8D, 0x56, 0xBA, 0x6D, 0x27, 0x45 } },
-        {39+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x54, 0x95, 0xC6, 0xAB, 0xF1, 0xE5, 0xDF, 0x51 } },
-        {40+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xAE, 0x13, 0xDB, 0xD5, 0x61, 0x48, 0x89, 0x33 } },
-        {41+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x02, 0x4D, 0x1F, 0xFA, 0x89, 0x04, 0xE3, 0x89 } },
-        {42+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xD1, 0x39, 0x97, 0x12, 0xF9, 0x9B, 0xF0, 0x2E } },
-        {43+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x14, 0xC1, 0xD7, 0xC1, 0xCF, 0xFE, 0xC7, 0x9E } },
-        {44+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x1D, 0xE5, 0x27, 0x9D, 0xAE, 0x3B, 0xED, 0x6F } },
-        {45+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xE9, 0x41, 0xA3, 0x3F, 0x85, 0x50, 0x13, 0x03 } },
-        {46+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xDA, 0x99, 0xDB, 0xBC, 0x9A, 0x03, 0xF3, 0x79 } },
-        {47+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xB7, 0xFC, 0x92, 0xF9, 0x1D, 0x8E, 0x92, 0xE9 } },
-        {48+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xAE, 0x8E, 0x5C, 0xAA, 0x3C, 0xA0, 0x4E, 0x85 } },
-        {49+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x9C, 0xC6, 0x2D, 0xF4, 0x3B, 0x6E, 0xED, 0x74 } },
-        {50+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xD8, 0x63, 0xDB, 0xB5, 0xC5, 0x9A, 0x91, 0xA0 } },
-        {51+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xA1, 0xAB, 0x21, 0x90, 0x54, 0x5B, 0x91, 0xD7 } },
-        {52+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x08, 0x75, 0x04, 0x1E, 0x64, 0xC5, 0x70, 0xF7 } },
-        {53+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x5A, 0x59, 0x45, 0x28, 0xBE, 0xBE, 0xF1, 0xCC } },
-        {54+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0xFC, 0xDB, 0x32, 0x91, 0xDE, 0x21, 0xF0, 0xC0 } },
-        {55+11, 0,  { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 },
-                    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-                    { 0x86, 0x9E, 0xFD, 0x7F, 0x9F, 0x26, 0x5A, 0x09 } },
-#endif /* LTC_TEST_EXT */
+        { { 0x10, 0x31, 0x6E, 0x02, 0x8C, 0x8F, 0x3B, 0x4A },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x82, 0xDC, 0xBA, 0xFB, 0xDE, 0xAB, 0x66, 0x02 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x95, 0xF8, 0xA5, 0xE5, 0xDD, 0x31, 0xD9, 0x00 },
+          { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0xDD, 0x7F, 0x12, 0x1C, 0xA5, 0x01, 0x56, 0x19 },
+          { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x2E, 0x86, 0x53, 0x10, 0x4F, 0x38, 0x34, 0xEA },
+          { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x4B, 0xD3, 0x88, 0xFF, 0x6C, 0xD8, 0x1D, 0x4F },
+          { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x20, 0xB9, 0xE7, 0x67, 0xB2, 0xFB, 0x14, 0x56 },
+          { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x55, 0x57, 0x93, 0x80, 0xD7, 0x71, 0x38, 0xEF },
+          { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x6C, 0xC5, 0xDE, 0xFA, 0xAF, 0x04, 0x51, 0x2F },
+          { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x0D, 0x9F, 0x27, 0x9B, 0xA5, 0xD8, 0x72, 0x60 },
+          { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0xD9, 0x03, 0x1B, 0x02, 0x71, 0xBD, 0x5A, 0x0A },
+          { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+
+        { { 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x95, 0xA8, 0xD7, 0x28, 0x13, 0xDA, 0xA9, 0x4D } },
+        { { 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x0E, 0xEC, 0x14, 0x87, 0xDD, 0x8C, 0x26, 0xD5 } },
+        { { 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x7A, 0xD1, 0x6F, 0xFB, 0x79, 0xC4, 0x59, 0x26 } },
+        { { 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xD3, 0x74, 0x62, 0x94, 0xCA, 0x6A, 0x6C, 0xF3 } },
+        { { 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x80, 0x9F, 0x5F, 0x87, 0x3C, 0x1F, 0xD7, 0x61 } },
+        { { 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xC0, 0x2F, 0xAF, 0xFE, 0xC9, 0x89, 0xD1, 0xFC } },
+        { { 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x46, 0x15, 0xAA, 0x1D, 0x33, 0xE7, 0x2F, 0x10 } },
+        { { 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x20, 0x55, 0x12, 0x33, 0x50, 0xC0, 0x08, 0x58 } },
+        { { 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xDF, 0x3B, 0x99, 0xD6, 0x57, 0x73, 0x97, 0xC8 } },
+        { { 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x31, 0xFE, 0x17, 0x36, 0x9B, 0x52, 0x88, 0xC9 } },
+        { { 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xDF, 0xDD, 0x3C, 0xC6, 0x4D, 0xAE, 0x16, 0x42 } },
+        { { 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x17, 0x8C, 0x83, 0xCE, 0x2B, 0x39, 0x9D, 0x94 } },
+        { { 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x50, 0xF6, 0x36, 0x32, 0x4A, 0x9B, 0x7F, 0x80 } },
+        { { 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xA8, 0x46, 0x8E, 0xE3, 0xBC, 0x18, 0xF0, 0x6D } },
+        { { 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xA2, 0xDC, 0x9E, 0x92, 0xFD, 0x3C, 0xDE, 0x92 } },
+        { { 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xCA, 0xC0, 0x9F, 0x79, 0x7D, 0x03, 0x12, 0x87 } },
+        { { 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x90, 0xBA, 0x68, 0x0B, 0x22, 0xAE, 0xB5, 0x25 } },
+        { { 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xCE, 0x7A, 0x24, 0xF3, 0x50, 0xE2, 0x80, 0xB6 } },
+        { { 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x88, 0x2B, 0xFF, 0x0A, 0xA0, 0x1A, 0x0B, 0x87 } },
+        { { 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x25, 0x61, 0x02, 0x88, 0x92, 0x45, 0x11, 0xC2 } },
+        { { 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xC7, 0x15, 0x16, 0xC2, 0x9C, 0x75, 0xD1, 0x70 } },
+        { { 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x51, 0x99, 0xC2, 0x9A, 0x52, 0xC9, 0xF0, 0x59 } },
+        { { 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xC2, 0x2F, 0x0A, 0x29, 0x4A, 0x71, 0xF2, 0x9F } },
+        { { 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xEE, 0x37, 0x14, 0x83, 0x71, 0x4C, 0x02, 0xEA } },
+        { { 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xA8, 0x1F, 0xBD, 0x44, 0x8F, 0x9E, 0x52, 0x2F } },
+        { { 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x4F, 0x64, 0x4C, 0x92, 0xE1, 0x92, 0xDF, 0xED } },
+        { { 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x1A, 0xFA, 0x9A, 0x66, 0xA6, 0xDF, 0x92, 0xAE } },
+        { { 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xB3, 0xC1, 0xCC, 0x71, 0x5C, 0xB8, 0x79, 0xD8 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x19, 0xD0, 0x32, 0xE6, 0x4A, 0xB0, 0xBD, 0x8B } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x3C, 0xFA, 0xA7, 0xA7, 0xDC, 0x87, 0x20, 0xDC } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xB7, 0x26, 0x5F, 0x7F, 0x44, 0x7A, 0xC6, 0xF3 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x9D, 0xB7, 0x3B, 0x3C, 0x0D, 0x16, 0x3F, 0x54 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x81, 0x81, 0xB6, 0x5B, 0xAB, 0xF4, 0xA9, 0x75 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x93, 0xC9, 0xB6, 0x40, 0x42, 0xEA, 0xA2, 0x40 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x55, 0x70, 0x53, 0x08, 0x29, 0x70, 0x55, 0x92 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x86, 0x38, 0x80, 0x9E, 0x87, 0x87, 0x87, 0xA0 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x41, 0xB9, 0xA7, 0x9A, 0xF7, 0x9A, 0xC2, 0x08 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x7A, 0x9B, 0xE4, 0x2F, 0x20, 0x09, 0xA8, 0x92 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x29, 0x03, 0x8D, 0x56, 0xBA, 0x6D, 0x27, 0x45 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x54, 0x95, 0xC6, 0xAB, 0xF1, 0xE5, 0xDF, 0x51 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xAE, 0x13, 0xDB, 0xD5, 0x61, 0x48, 0x89, 0x33 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x02, 0x4D, 0x1F, 0xFA, 0x89, 0x04, 0xE3, 0x89 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xD1, 0x39, 0x97, 0x12, 0xF9, 0x9B, 0xF0, 0x2E } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x14, 0xC1, 0xD7, 0xC1, 0xCF, 0xFE, 0xC7, 0x9E } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x1D, 0xE5, 0x27, 0x9D, 0xAE, 0x3B, 0xED, 0x6F } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xE9, 0x41, 0xA3, 0x3F, 0x85, 0x50, 0x13, 0x03 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xDA, 0x99, 0xDB, 0xBC, 0x9A, 0x03, 0xF3, 0x79 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xB7, 0xFC, 0x92, 0xF9, 0x1D, 0x8E, 0x92, 0xE9 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xAE, 0x8E, 0x5C, 0xAA, 0x3C, 0xA0, 0x4E, 0x85 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x9C, 0xC6, 0x2D, 0xF4, 0x3B, 0x6E, 0xED, 0x74 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xD8, 0x63, 0xDB, 0xB5, 0xC5, 0x9A, 0x91, 0xA0 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xA1, 0xAB, 0x21, 0x90, 0x54, 0x5B, 0x91, 0xD7 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x08, 0x75, 0x04, 0x1E, 0x64, 0xC5, 0x70, 0xF7 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x5A, 0x59, 0x45, 0x28, 0xBE, 0xBE, 0xF1, 0xCC } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xFC, 0xDB, 0x32, 0x91, 0xDE, 0x21, 0xF0, 0xC0 } },
+        { { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x86, 0x9E, 0xFD, 0x7F, 0x9F, 0x26, 0x5A, 0x09 } },
 
 
         /*** more test cases you could add if you are not convinced (the above test cases aren't really too good):
         /*** more test cases you could add if you are not convinced (the above test cases aren't really too good):
 
 
@@ -1962,30 +1921,43 @@ int des_test(void)
             http://www.ecs.soton.ac.uk/~prw99r/ez438/vectors.txt
             http://www.ecs.soton.ac.uk/~prw99r/ez438/vectors.txt
         ***/
         ***/
     };
     };
-    int i, y;
-    unsigned char tmp[8];
-    symmetric_key des;
+    unsigned char key[8], pt[8], ct[8], tmp[8];
+    symmetric_key skey;
+    int i, err;
 
 
-    for(i=0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
+    for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
     {
     {
-        if ((err = des_setup(cases[i].key, 8, 0, &des)) != CRYPT_OK) {
-           return err;
+        if ((err = des_setup(cases[i].key, 8, 0, &skey)) != CRYPT_OK) {
+            return err;
         }
         }
-        if (cases[i].mode != 0) {
-           des_ecb_encrypt(cases[i].txt, tmp, &des);
-        } else {
-           des_ecb_decrypt(cases[i].txt, tmp, &des);
+
+        des_ecb_encrypt(cases[i].txt, ct, &skey);
+
+        if (compare_testvector(ct, sizeof(ct), cases[i].out, 8, "DES Encrypt", i) != 0) {
+            return CRYPT_FAIL_TESTVECTOR;
         }
         }
 
 
-        if (compare_testvector(cases[i].out, sizeof(tmp), tmp, sizeof(tmp), "DES", i) != 0) {
-           return CRYPT_FAIL_TESTVECTOR;
+        des_ecb_decrypt(ct, pt, &skey);
+
+        if (compare_testvector(pt, sizeof(pt), cases[i].txt, 8, "DES Decrypt", i) != 0) {
+            return CRYPT_FAIL_TESTVECTOR;
         }
         }
+    }
+
+    /* See if we can encrypt all zero bytes 1000 times, decrypt and come back to where we started */
 
 
-        /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
-        for (y = 0; y < 8; y++) tmp[y] = 0;
-        for (y = 0; y < 1000; y++) des_ecb_encrypt(tmp, tmp, &des);
-        for (y = 0; y < 1000; y++) des_ecb_decrypt(tmp, tmp, &des);
-        for (y = 0; y < 8; y++) if (tmp[y] != 0) return CRYPT_FAIL_TESTVECTOR;
+    for (i = 0; i < 8; i++) key[i] = i;
+
+    if ((err = des_setup(key, 8, 0, &skey)) != CRYPT_OK) {
+        return err;
+    }
+
+    for (i = 0; i < 8; i++) pt[i] = tmp[i] = 0;
+    for (i = 0; i < 1000; i++) des_ecb_encrypt(tmp, tmp, &skey);
+    for (i = 0; i < 1000; i++) des_ecb_decrypt(tmp, tmp, &skey);
+
+    if (compare_testvector(tmp, 8, pt, 8, "DES", 0) != 0) {
+        return CRYPT_FAIL_TESTVECTOR;
     }
     }
 
 
     return CRYPT_OK;
     return CRYPT_OK;
@@ -1997,34 +1969,72 @@ int des3_test(void)
  #ifndef LTC_TEST
  #ifndef LTC_TEST
     return CRYPT_NOP;
     return CRYPT_NOP;
  #else
  #else
-   unsigned char key[24], pt[8], ct[8], tmp[8];
-   symmetric_key skey;
-   int x, err;
+    static const struct des3_test_case {
+        unsigned char key[16], txt[8], out[8];
+    } cases[] = {
+        /*
+           https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/des/Triple-Des-2-Key-128-64.unverified.test-vectors
+        */
+        { { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xFA, 0xFD, 0x50, 0x84, 0x37, 0x4F, 0xCE, 0x34 } },
+        { { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x60, 0xCC, 0x37, 0xB7, 0xB5, 0x37, 0xA1, 0xDC } },
+        { { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+          { 0xBE, 0x3E, 0x73, 0x04, 0xFE, 0x92, 0xC2, 0xBC } },
+        { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 },
+          { 0xE5, 0xA9, 0xE3, 0x80, 0x03, 0xA5, 0xA0, 0xFD },
+          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+        { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+          { 0xE4, 0xFC, 0x19, 0xD6, 0x94, 0x63, 0xB7, 0x83 },
+          { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 } },
+    };
+    unsigned char key[24], pt[8], ct[8], tmp[8];
+    symmetric_key skey;
+    int i, err;
 
 
-   if ((err = des_test()) != CRYPT_OK) {
-      return err;
-   }
+    if ((err = des_test()) != CRYPT_OK) {
+        return err;
+    }
 
 
-   for (x = 0; x < 8; x++) {
-       pt[x] = x;
-   }
+    for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
+    {
+        if ((err = des3_setup(cases[i].key, 16, 0, &skey)) != CRYPT_OK) {
+            return err;
+        }
 
 
-   for (x = 0; x < 24; x++) {
-       key[x] = x;
-   }
+        des3_ecb_encrypt(cases[i].txt, ct, &skey);
 
 
-   if ((err = des3_setup(key, 24, 0, &skey)) != CRYPT_OK) {
-      return err;
-   }
+        if (compare_testvector(ct, sizeof(ct), cases[i].out, 8, "3DES Encrypt", i) != 0) {
+            return CRYPT_FAIL_TESTVECTOR;
+        }
 
 
-   des3_ecb_encrypt(pt, ct, &skey);
-   des3_ecb_decrypt(ct, tmp, &skey);
+        des3_ecb_decrypt(ct, pt, &skey);
 
 
-   if (compare_testvector(pt, 8, tmp, 8, "3DES", 0) != 0) {
-      return CRYPT_FAIL_TESTVECTOR;
-   }
+        if (compare_testvector(pt, sizeof(pt), cases[i].txt, 8, "3DES Decrypt", i) != 0) {
+            return CRYPT_FAIL_TESTVECTOR;
+        }
+    }
+
+    /* See if we can encrypt all zero bytes 1000 times, decrypt and come back to where we started */
 
 
-   return CRYPT_OK;
+    for (i = 0; i < 24; i++) key[i] = i;
+
+    if ((err = des3_setup(key, 24, 0, &skey)) != CRYPT_OK) {
+        return err;
+    }
+
+    for (i = 0; i < 8; i++) pt[i] = tmp[i] = 0;
+    for (i = 0; i < 1000; i++) des3_ecb_encrypt(tmp, tmp, &skey);
+    for (i = 0; i < 1000; i++) des3_ecb_decrypt(tmp, tmp, &skey);
+
+    if (compare_testvector(tmp, 8, pt, 8, "3DES", 0) != 0) {
+        return CRYPT_FAIL_TESTVECTOR;
+    }
+
+    return CRYPT_OK;
  #endif
  #endif
 }
 }
 
 
@@ -2081,7 +2091,3 @@ int des3_keysize(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 47 - 57
libtomcrypt.mod/libtomcrypt/src/ciphers/idea.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /* Based on idea.cpp - originally written and placed in the public domain by Wei Dai
 /* Based on idea.cpp - originally written and placed in the public domain by Wei Dai
    https://github.com/weidai11/cryptopp/blob/master/idea.cpp
    https://github.com/weidai11/cryptopp/blob/master/idea.cpp
@@ -41,38 +35,38 @@ const struct ltc_cipher_descriptor idea_desc = {
 
 
 typedef unsigned short int ushort16;
 typedef unsigned short int ushort16;
 
 
-#define _LOW16(x)     ((x)&0xffff)  /* compiler should be able to optimize this away if x is 16 bits */
-#define _HIGH16(x)    ((x)>>16)
-#define _MUL(a,b)     {                                               \
-                         ulong32 p = (ulong32)_LOW16(a) * b;          \
+#define LOW16(x)     ((x)&0xffff)  /* compiler should be able to optimize this away if x is 16 bits */
+#define HIGH16(x)    ((x)>>16)
+#define MUL(a,b)     {                                               \
+                         ulong32 p = (ulong32)LOW16(a) * b;          \
                          if (p) {                                     \
                          if (p) {                                     \
-                            p = _LOW16(p) - _HIGH16(p);               \
-                            a = (ushort16)p - (ushort16)_HIGH16(p);   \
+                            p = LOW16(p) - HIGH16(p);               \
+                            a = (ushort16)p - (ushort16)HIGH16(p);   \
                          }                                            \
                          }                                            \
                          else                                         \
                          else                                         \
                             a = 1 - a - b;                            \
                             a = 1 - a - b;                            \
                       }
                       }
-#define _STORE16(x,y) { (y)[0] = (unsigned char)(((x)>>8)&255); (y)[1] = (unsigned char)((x)&255); }
-#define _LOAD16(x,y)  { x = ((ushort16)((y)[0] & 255)<<8) | ((ushort16)((y)[1] & 255)); }
+#define STORE16(x,y) { (y)[0] = (unsigned char)(((x)>>8)&255); (y)[1] = (unsigned char)((x)&255); }
+#define LOAD16(x,y)  { x = ((ushort16)((y)[0] & 255)<<8) | ((ushort16)((y)[1] & 255)); }
 
 
-static ushort16 _mul_inv(ushort16 x)
+static ushort16 s_mul_inv(ushort16 x)
 {
 {
    ushort16 y = x;
    ushort16 y = x;
    unsigned i;
    unsigned i;
 
 
    for (i = 0; i < 15; i++) {
    for (i = 0; i < 15; i++) {
-      _MUL(y, _LOW16(y));
-      _MUL(y, x);
+      MUL(y, LOW16(y));
+      MUL(y, x);
    }
    }
-   return _LOW16(y);
+   return LOW16(y);
 }
 }
 
 
-static ushort16 _add_inv(ushort16 x)
+static ushort16 s_add_inv(ushort16 x)
 {
 {
-   return _LOW16(0 - x);
+   return LOW16(0 - x);
 }
 }
 
 
-static int _setup_key(const unsigned char *key, symmetric_key *skey)
+static int s_setup_key(const unsigned char *key, symmetric_key *skey)
 {
 {
    int i, j;
    int i, j;
    ushort16 *e_key = skey->idea.ek;
    ushort16 *e_key = skey->idea.ek;
@@ -80,49 +74,49 @@ static int _setup_key(const unsigned char *key, symmetric_key *skey)
 
 
    /* prepare enc key */
    /* prepare enc key */
    for (i = 0; i < 8; i++) {
    for (i = 0; i < 8; i++) {
-      _LOAD16(e_key[i], key + 2 * i);
+      LOAD16(e_key[i], key + 2 * i);
    }
    }
    for (; i < LTC_IDEA_KEYLEN; i++) {
    for (; i < LTC_IDEA_KEYLEN; i++) {
       j = (i - i % 8) - 8;
       j = (i - i % 8) - 8;
-      e_key[i] = _LOW16((e_key[j+(i+1)%8] << 9) | (e_key[j+(i+2)%8] >> 7));
+      e_key[i] = LOW16((e_key[j+(i+1)%8] << 9) | (e_key[j+(i+2)%8] >> 7));
    }
    }
 
 
    /* prepare dec key */
    /* prepare dec key */
    for (i = 0; i < LTC_IDEA_ROUNDS; i++) {
    for (i = 0; i < LTC_IDEA_ROUNDS; i++) {
-      d_key[i*6+0] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
-      d_key[i*6+1] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1+(i>0 ? 1 : 0)]);
-      d_key[i*6+2] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2-(i>0 ? 1 : 0)]);
-      d_key[i*6+3] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
-      d_key[i*6+4] =          e_key[(LTC_IDEA_ROUNDS-1-i)*6+4];
-      d_key[i*6+5] =          e_key[(LTC_IDEA_ROUNDS-1-i)*6+5];
+      d_key[i*6+0] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
+      d_key[i*6+1] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1+(i>0 ? 1 : 0)]);
+      d_key[i*6+2] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2-(i>0 ? 1 : 0)]);
+      d_key[i*6+3] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
+      d_key[i*6+4] =           e_key[(LTC_IDEA_ROUNDS-1-i)*6+4];
+      d_key[i*6+5] =           e_key[(LTC_IDEA_ROUNDS-1-i)*6+5];
    }
    }
-   d_key[i*6+0] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
-   d_key[i*6+1] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1]);
-   d_key[i*6+2] = _add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2]);
-   d_key[i*6+3] = _mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
+   d_key[i*6+0] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+0]);
+   d_key[i*6+1] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+1]);
+   d_key[i*6+2] = s_add_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+2]);
+   d_key[i*6+3] = s_mul_inv(e_key[(LTC_IDEA_ROUNDS-i)*6+3]);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-static int _process_block(const unsigned char *in, unsigned char *out, const ushort16 *m_key)
+static int s_process_block(const unsigned char *in, unsigned char *out, const ushort16 *m_key)
 {
 {
    int i;
    int i;
    ushort16 x0, x1, x2, x3, t0, t1;
    ushort16 x0, x1, x2, x3, t0, t1;
 
 
-   _LOAD16(x0, in + 0);
-   _LOAD16(x1, in + 2);
-   _LOAD16(x2, in + 4);
-   _LOAD16(x3, in + 6);
+   LOAD16(x0, in + 0);
+   LOAD16(x1, in + 2);
+   LOAD16(x2, in + 4);
+   LOAD16(x3, in + 6);
 
 
    for (i = 0; i < LTC_IDEA_ROUNDS; i++) {
    for (i = 0; i < LTC_IDEA_ROUNDS; i++) {
-      _MUL(x0, m_key[i*6+0]);
+      MUL(x0, m_key[i*6+0]);
       x1 += m_key[i*6+1];
       x1 += m_key[i*6+1];
       x2 += m_key[i*6+2];
       x2 += m_key[i*6+2];
-      _MUL(x3, m_key[i*6+3]);
+      MUL(x3, m_key[i*6+3]);
       t0 = x0^x2;
       t0 = x0^x2;
-      _MUL(t0, m_key[i*6+4]);
+      MUL(t0, m_key[i*6+4]);
       t1 = t0 + (x1^x3);
       t1 = t0 + (x1^x3);
-      _MUL(t1, m_key[i*6+5]);
+      MUL(t1, m_key[i*6+5]);
       t0 += t1;
       t0 += t1;
       x0 ^= t1;
       x0 ^= t1;
       x3 ^= t0;
       x3 ^= t0;
@@ -131,15 +125,15 @@ static int _process_block(const unsigned char *in, unsigned char *out, const ush
       x2 = t0;
       x2 = t0;
    }
    }
 
 
-   _MUL(x0, m_key[LTC_IDEA_ROUNDS*6+0]);
+   MUL(x0, m_key[LTC_IDEA_ROUNDS*6+0]);
    x2 += m_key[LTC_IDEA_ROUNDS*6+1];
    x2 += m_key[LTC_IDEA_ROUNDS*6+1];
    x1 += m_key[LTC_IDEA_ROUNDS*6+2];
    x1 += m_key[LTC_IDEA_ROUNDS*6+2];
-   _MUL(x3, m_key[LTC_IDEA_ROUNDS*6+3]);
+   MUL(x3, m_key[LTC_IDEA_ROUNDS*6+3]);
 
 
-   _STORE16(x0, out + 0);
-   _STORE16(x2, out + 2);
-   _STORE16(x1, out + 4);
-   _STORE16(x3, out + 6);
+   STORE16(x0, out + 0);
+   STORE16(x2, out + 2);
+   STORE16(x1, out + 4);
+   STORE16(x3, out + 6);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
@@ -152,12 +146,12 @@ int idea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
    if (num_rounds != 0 && num_rounds != 8) return CRYPT_INVALID_ROUNDS;
    if (num_rounds != 0 && num_rounds != 8) return CRYPT_INVALID_ROUNDS;
    if (keylen != 16) return CRYPT_INVALID_KEYSIZE;
    if (keylen != 16) return CRYPT_INVALID_KEYSIZE;
 
 
-   return _setup_key(key, skey);
+   return s_setup_key(key, skey);
 }
 }
 
 
 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _process_block(pt, ct, skey->idea.ek);
+   int err = s_process_block(pt, ct, skey->idea.ek);
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    burn_stack(sizeof(ushort16) * 6 + sizeof(int));
    burn_stack(sizeof(ushort16) * 6 + sizeof(int));
 #endif
 #endif
@@ -166,7 +160,7 @@ int idea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric
 
 
 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int idea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _process_block(ct, pt, skey->idea.dk);
+   int err = s_process_block(ct, pt, skey->idea.dk);
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    burn_stack(sizeof(ushort16) * 6 + sizeof(int));
    burn_stack(sizeof(ushort16) * 6 + sizeof(int));
 #endif
 #endif
@@ -254,7 +248,3 @@ int idea_test(void)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 2 - 12
libtomcrypt.mod/libtomcrypt/src/ciphers/kasumi.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file kasumi.c
   @file kasumi.c
@@ -311,7 +305,3 @@ int kasumi_test(void)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 2 - 12
libtomcrypt.mod/libtomcrypt/src/ciphers/khazad.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 #include "tomcrypt_private.h"
 #include "tomcrypt_private.h"
 
 
 /**
 /**
@@ -844,7 +838,3 @@ int khazad_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 2 - 12
libtomcrypt.mod/libtomcrypt/src/ciphers/kseed.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file kseed.c
   @file kseed.c
@@ -370,7 +364,3 @@ int kseed_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 29 - 39
libtomcrypt.mod/libtomcrypt/src/ciphers/multi2.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file multi2.c
   @file multi2.c
@@ -15,12 +9,12 @@
 
 
 #ifdef LTC_MULTI2
 #ifdef LTC_MULTI2
 
 
-static void pi1(ulong32 *p)
+static void s_pi1(ulong32 *p)
 {
 {
    p[1] ^= p[0];
    p[1] ^= p[0];
 }
 }
 
 
-static void pi2(ulong32 *p, const ulong32 *k)
+static void s_pi2(ulong32 *p, const ulong32 *k)
 {
 {
    ulong32 t;
    ulong32 t;
    t = (p[1] + k[0]) & 0xFFFFFFFFUL;
    t = (p[1] + k[0]) & 0xFFFFFFFFUL;
@@ -29,7 +23,7 @@ static void pi2(ulong32 *p, const ulong32 *k)
    p[0] ^= t;
    p[0] ^= t;
 }
 }
 
 
-static void pi3(ulong32 *p, const ulong32 *k)
+static void s_pi3(ulong32 *p, const ulong32 *k)
 {
 {
    ulong32 t;
    ulong32 t;
    t = p[0] + k[1];
    t = p[0] + k[1];
@@ -41,7 +35,7 @@ static void pi3(ulong32 *p, const ulong32 *k)
    p[1] ^= t;
    p[1] ^= t;
 }
 }
 
 
-static void pi4(ulong32 *p, const ulong32 *k)
+static void s_pi4(ulong32 *p, const ulong32 *k)
 {
 {
    ulong32 t;
    ulong32 t;
    t = (p[1] + k[3])  & 0xFFFFFFFFUL;
    t = (p[1] + k[3])  & 0xFFFFFFFFUL;
@@ -49,7 +43,7 @@ static void pi4(ulong32 *p, const ulong32 *k)
    p[0] ^= t;
    p[0] ^= t;
 }
 }
 
 
-static void setup(const ulong32 *dk, const ulong32 *k, ulong32 *uk)
+static void s_setup(const ulong32 *dk, const ulong32 *k, ulong32 *uk)
 {
 {
    int n, t;
    int n, t;
    ulong32 p[2];
    ulong32 p[2];
@@ -58,46 +52,46 @@ static void setup(const ulong32 *dk, const ulong32 *k, ulong32 *uk)
 
 
    t = 4;
    t = 4;
    n = 0;
    n = 0;
-      pi1(p);
-      pi2(p, k);
+      s_pi1(p);
+      s_pi2(p, k);
       uk[n++] = p[0];
       uk[n++] = p[0];
-      pi3(p, k);
+      s_pi3(p, k);
       uk[n++] = p[1];
       uk[n++] = p[1];
-      pi4(p, k);
+      s_pi4(p, k);
       uk[n++] = p[0];
       uk[n++] = p[0];
-      pi1(p);
+      s_pi1(p);
       uk[n++] = p[1];
       uk[n++] = p[1];
-      pi2(p, k+t);
+      s_pi2(p, k+t);
       uk[n++] = p[0];
       uk[n++] = p[0];
-      pi3(p, k+t);
+      s_pi3(p, k+t);
       uk[n++] = p[1];
       uk[n++] = p[1];
-      pi4(p, k+t);
+      s_pi4(p, k+t);
       uk[n++] = p[0];
       uk[n++] = p[0];
-      pi1(p);
+      s_pi1(p);
       uk[n++] = p[1];
       uk[n++] = p[1];
 }
 }
 
 
-static void encrypt(ulong32 *p, int N, const ulong32 *uk)
+static void s_encrypt(ulong32 *p, int N, const ulong32 *uk)
 {
 {
    int n, t;
    int n, t;
    for (t = n = 0; ; ) {
    for (t = n = 0; ; ) {
-      pi1(p); if (++n == N) break;
-      pi2(p, uk+t); if (++n == N) break;
-      pi3(p, uk+t); if (++n == N) break;
-      pi4(p, uk+t); if (++n == N) break;
+      s_pi1(p); if (++n == N) break;
+      s_pi2(p, uk+t); if (++n == N) break;
+      s_pi3(p, uk+t); if (++n == N) break;
+      s_pi4(p, uk+t); if (++n == N) break;
       t ^= 4;
       t ^= 4;
    }
    }
 }
 }
 
 
-static void decrypt(ulong32 *p, int N, const ulong32 *uk)
+static void s_decrypt(ulong32 *p, int N, const ulong32 *uk)
 {
 {
    int n, t;
    int n, t;
    for (t = 4*(((N-1)>>2)&1), n = N; ;  ) {
    for (t = 4*(((N-1)>>2)&1), n = N; ;  ) {
       switch (n<=4 ? n : ((n-1)%4)+1) {
       switch (n<=4 ? n : ((n-1)%4)+1) {
-         case 4: pi4(p, uk+t); --n; /* FALLTHROUGH */
-         case 3: pi3(p, uk+t); --n; /* FALLTHROUGH */
-         case 2: pi2(p, uk+t); --n; /* FALLTHROUGH */
-         case 1: pi1(p); --n; break;
+         case 4: s_pi4(p, uk+t); --n; /* FALLTHROUGH */
+         case 3: s_pi3(p, uk+t); --n; /* FALLTHROUGH */
+         case 2: s_pi2(p, uk+t); --n; /* FALLTHROUGH */
+         case 1: s_pi1(p); --n; break;
          case 0: return;
          case 0: return;
       }
       }
       t ^= 4;
       t ^= 4;
@@ -134,7 +128,7 @@ int  multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
    }
    }
    LOAD32H(dk[0], key + 32);
    LOAD32H(dk[0], key + 32);
    LOAD32H(dk[1], key + 36);
    LOAD32H(dk[1], key + 36);
-   setup(dk, sk, skey->multi2.uk);
+   s_setup(dk, sk, skey->multi2.uk);
 
 
    zeromem(sk, sizeof(sk));
    zeromem(sk, sizeof(sk));
    zeromem(dk, sizeof(dk));
    zeromem(dk, sizeof(dk));
@@ -156,7 +150,7 @@ int multi2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetr
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
    LOAD32H(p[0], pt);
    LOAD32H(p[0], pt);
    LOAD32H(p[1], pt+4);
    LOAD32H(p[1], pt+4);
-   encrypt(p, skey->multi2.N, skey->multi2.uk);
+   s_encrypt(p, skey->multi2.N, skey->multi2.uk);
    STORE32H(p[0], ct);
    STORE32H(p[0], ct);
    STORE32H(p[1], ct+4);
    STORE32H(p[1], ct+4);
    return CRYPT_OK;
    return CRYPT_OK;
@@ -177,7 +171,7 @@ int multi2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetr
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
    LOAD32H(p[0], ct);
    LOAD32H(p[0], ct);
    LOAD32H(p[1], ct+4);
    LOAD32H(p[1], ct+4);
-   decrypt(p, skey->multi2.N, skey->multi2.uk);
+   s_decrypt(p, skey->multi2.N, skey->multi2.uk);
    STORE32H(p[0], pt);
    STORE32H(p[0], pt);
    STORE32H(p[1], pt+4);
    STORE32H(p[1], pt+4);
    return CRYPT_OK;
    return CRYPT_OK;
@@ -313,7 +307,3 @@ int multi2_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 6 - 16
libtomcrypt.mod/libtomcrypt/src/ciphers/noekeon.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 /**
 /**
    @file noekeon.c
    @file noekeon.c
    Implementation of the Noekeon block cipher by Tom St Denis
    Implementation of the Noekeon block cipher by Tom St Denis
@@ -108,7 +102,7 @@ int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -148,7 +142,7 @@ int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _noekeon_ecb_encrypt(pt, ct, skey);
+   int err = s_noekeon_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -162,7 +156,7 @@ int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -201,7 +195,7 @@ int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmet
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _noekeon_ecb_decrypt(ct, pt, skey);
+   int err = s_noekeon_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -321,7 +315,3 @@ int noekeon_keysize(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 6 - 16
libtomcrypt.mod/libtomcrypt/src/ciphers/rc2.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 /**********************************************************************\
 /**********************************************************************\
 * To commemorate the 1996 RSA Data Security Conference, the following  *
 * To commemorate the 1996 RSA Data Security Conference, the following  *
 * code is released into the public domain by its author.  Prost!       *
 * code is released into the public domain by its author.  Prost!       *
@@ -145,7 +139,7 @@ int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc2_ecb_encrypt( const unsigned char *pt,
+static int s_rc2_ecb_encrypt( const unsigned char *pt,
                             unsigned char *ct,
                             unsigned char *ct,
                             const symmetric_key *skey)
                             const symmetric_key *skey)
 #else
 #else
@@ -206,7 +200,7 @@ int rc2_ecb_encrypt( const unsigned char *pt,
                             unsigned char *ct,
                             unsigned char *ct,
                             const symmetric_key *skey)
                             const symmetric_key *skey)
 {
 {
-    int err = _rc2_ecb_encrypt(pt, ct, skey);
+    int err = s_rc2_ecb_encrypt(pt, ct, skey);
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
     return err;
     return err;
 }
 }
@@ -223,7 +217,7 @@ int rc2_ecb_encrypt( const unsigned char *pt,
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc2_ecb_decrypt( const unsigned char *ct,
+static int s_rc2_ecb_decrypt( const unsigned char *ct,
                             unsigned char *pt,
                             unsigned char *pt,
                             const symmetric_key *skey)
                             const symmetric_key *skey)
 #else
 #else
@@ -285,7 +279,7 @@ int rc2_ecb_decrypt( const unsigned char *ct,
                             unsigned char *pt,
                             unsigned char *pt,
                             const symmetric_key *skey)
                             const symmetric_key *skey)
 {
 {
-    int err = _rc2_ecb_decrypt(ct, pt, skey);
+    int err = s_rc2_ecb_decrypt(ct, pt, skey);
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
     return err;
     return err;
 }
 }
@@ -412,7 +406,3 @@ int rc2_keysize(int *keysize)
 
 
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 16 - 18
libtomcrypt.mod/libtomcrypt/src/ciphers/rc5.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
    @file rc5.c
    @file rc5.c
@@ -49,7 +43,7 @@ static const ulong32 stab[50] = {
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+static int s_rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 #else
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #endif
 #endif
@@ -110,7 +104,7 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
 {
    int x;
    int x;
-   x = _rc5_setup(key, keylen, num_rounds, skey);
+   x = s_rc5_setup(key, keylen, num_rounds, skey);
    burn_stack(sizeof(ulong32) * 122 + sizeof(int));
    burn_stack(sizeof(ulong32) * 122 + sizeof(int));
    return x;
    return x;
 }
 }
@@ -124,7 +118,7 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -136,6 +130,10 @@ int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
 
 
+   if (skey->rc5.rounds < 12 || skey->rc5.rounds > 24) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
    LOAD32L(A, &pt[0]);
    LOAD32L(A, &pt[0]);
    LOAD32L(B, &pt[4]);
    LOAD32L(B, &pt[4]);
    A += skey->rc5.K[0];
    A += skey->rc5.K[0];
@@ -166,7 +164,7 @@ int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _rc5_ecb_encrypt(pt, ct, skey);
+   int err = s_rc5_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -180,7 +178,7 @@ int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -192,6 +190,10 @@ int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
 
 
+   if (skey->rc5.rounds < 12 || skey->rc5.rounds > 24) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
    LOAD32L(A, &ct[0]);
    LOAD32L(A, &ct[0]);
    LOAD32L(B, &ct[4]);
    LOAD32L(B, &ct[4]);
    K = skey->rc5.K + (skey->rc5.rounds << 1);
    K = skey->rc5.K + (skey->rc5.rounds << 1);
@@ -223,7 +225,7 @@ int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _rc5_ecb_decrypt(ct, pt, skey);
+   int err = s_rc5_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -319,7 +321,3 @@ int rc5_keysize(int *keysize)
 
 
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 8 - 18
libtomcrypt.mod/libtomcrypt/src/ciphers/rc6.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
    @file rc6.c
    @file rc6.c
@@ -46,7 +40,7 @@ static const ulong32 stab[44] = {
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+static int s_rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 #else
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #endif
 #endif
@@ -105,7 +99,7 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
 {
    int x;
    int x;
-   x = _rc6_setup(key, keylen, num_rounds, skey);
+   x = s_rc6_setup(key, keylen, num_rounds, skey);
    burn_stack(sizeof(ulong32) * 122);
    burn_stack(sizeof(ulong32) * 122);
    return x;
    return x;
 }
 }
@@ -118,7 +112,7 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
   @param skey The key as scheduled
   @param skey The key as scheduled
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -160,7 +154,7 @@ int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _rc6_ecb_encrypt(pt, ct, skey);
+   int err = s_rc6_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -173,7 +167,7 @@ int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_
   @param skey The key as scheduled
   @param skey The key as scheduled
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -217,7 +211,7 @@ int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _rc6_ecb_decrypt(ct, pt, skey);
+   int err = s_rc6_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -328,7 +322,3 @@ int rc6_keysize(int *keysize)
 #endif /*LTC_RC6*/
 #endif /*LTC_RC6*/
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 15 - 25
libtomcrypt.mod/libtomcrypt/src/ciphers/safer/safer.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /*******************************************************************************
 /*******************************************************************************
 *
 *
@@ -30,7 +24,7 @@
 
 
 #ifdef LTC_SAFER
 #ifdef LTC_SAFER
 
 
-#define __LTC_SAFER_TAB_C__
+#define LTC_SAFER_TAB_C
 #include "safer_tab.c"
 #include "safer_tab.c"
 
 
 const struct ltc_cipher_descriptor safer_k64_desc = {
 const struct ltc_cipher_descriptor safer_k64_desc = {
@@ -97,13 +91,13 @@ const struct ltc_cipher_descriptor safer_k64_desc = {
 /******************* Types ****************************************************/
 /******************* Types ****************************************************/
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static void _Safer_Expand_Userkey(const unsigned char *userkey_1,
+static void s_safer_expand_userkey(const unsigned char *userkey_1,
                                  const unsigned char *userkey_2,
                                  const unsigned char *userkey_2,
                                  unsigned int nof_rounds,
                                  unsigned int nof_rounds,
                                  int strengthened,
                                  int strengthened,
                                  safer_key_t key)
                                  safer_key_t key)
 #else
 #else
-static void Safer_Expand_Userkey(const unsigned char *userkey_1,
+static void safer_expand_userkey(const unsigned char *userkey_1,
                                  const unsigned char *userkey_2,
                                  const unsigned char *userkey_2,
                                  unsigned int nof_rounds,
                                  unsigned int nof_rounds,
                                  int strengthened,
                                  int strengthened,
@@ -166,13 +160,13 @@ static void Safer_Expand_Userkey(const unsigned char *userkey_1,
 }
 }
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static void Safer_Expand_Userkey(const unsigned char *userkey_1,
+static void safer_expand_userkey(const unsigned char *userkey_1,
                                  const unsigned char *userkey_2,
                                  const unsigned char *userkey_2,
                                  unsigned int nof_rounds,
                                  unsigned int nof_rounds,
                                  int strengthened,
                                  int strengthened,
                                  safer_key_t key)
                                  safer_key_t key)
 {
 {
-   _Safer_Expand_Userkey(userkey_1, userkey_2, nof_rounds, strengthened, key);
+   s_safer_expand_userkey(userkey_1, userkey_2, nof_rounds, strengthened, key);
    burn_stack(sizeof(unsigned char) * (2 * (LTC_SAFER_BLOCK_LEN + 1)) + sizeof(unsigned int)*2);
    burn_stack(sizeof(unsigned char) * (2 * (LTC_SAFER_BLOCK_LEN + 1)) + sizeof(unsigned int)*2);
 }
 }
 #endif
 #endif
@@ -190,7 +184,7 @@ int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmet
       return CRYPT_INVALID_KEYSIZE;
       return CRYPT_INVALID_KEYSIZE;
    }
    }
 
 
-   Safer_Expand_Userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K64_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
+   safer_expand_userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K64_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
@@ -207,7 +201,7 @@ int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symme
       return CRYPT_INVALID_KEYSIZE;
       return CRYPT_INVALID_KEYSIZE;
    }
    }
 
 
-   Safer_Expand_Userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
+   safer_expand_userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
@@ -224,7 +218,7 @@ int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symme
       return CRYPT_INVALID_KEYSIZE;
       return CRYPT_INVALID_KEYSIZE;
    }
    }
 
 
-   Safer_Expand_Userkey(key, key+8, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K128_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
+   safer_expand_userkey(key, key+8, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K128_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
@@ -241,12 +235,12 @@ int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symm
       return CRYPT_INVALID_KEYSIZE;
       return CRYPT_INVALID_KEYSIZE;
    }
    }
 
 
-   Safer_Expand_Userkey(key, key+8, (unsigned int)(num_rounds != 0?num_rounds:LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
+   safer_expand_userkey(key, key+8, (unsigned int)(num_rounds != 0?num_rounds:LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _safer_ecb_encrypt(const unsigned char *pt,
+static int s_safer_ecb_encrypt(const unsigned char *pt,
                              unsigned char *ct,
                              unsigned char *ct,
                              const symmetric_key *skey)
                              const symmetric_key *skey)
 #else
 #else
@@ -293,14 +287,14 @@ int safer_ecb_encrypt(const unsigned char *pt,
                              unsigned char *ct,
                              unsigned char *ct,
                              const symmetric_key *skey)
                              const symmetric_key *skey)
 {
 {
-    int err = _safer_ecb_encrypt(pt, ct, skey);
+    int err = s_safer_ecb_encrypt(pt, ct, skey);
     burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
     burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
     return err;
     return err;
 }
 }
 #endif
 #endif
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _safer_ecb_decrypt(const unsigned char *ct,
+static int s_safer_ecb_decrypt(const unsigned char *ct,
                              unsigned char *pt,
                              unsigned char *pt,
                              const symmetric_key *skey)
                              const symmetric_key *skey)
 #else
 #else
@@ -348,7 +342,7 @@ int safer_ecb_decrypt(const unsigned char *ct,
                              unsigned char *pt,
                              unsigned char *pt,
                              const symmetric_key *skey)
                              const symmetric_key *skey)
 {
 {
-    int err = _safer_ecb_decrypt(ct, pt, skey);
+    int err = s_safer_ecb_decrypt(ct, pt, skey);
     burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
     burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
     return err;
     return err;
 }
 }
@@ -488,7 +482,3 @@ int safer_sk128_test(void)
 
 
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 4 - 14
libtomcrypt.mod/libtomcrypt/src/ciphers/safer/safer_tab.c

@@ -1,18 +1,12 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file safer_tab.c
   @file safer_tab.c
   Tables for LTC_SAFER block ciphers
   Tables for LTC_SAFER block ciphers
 */
 */
 
 
-#ifdef __LTC_SAFER_TAB_C__
+#ifdef LTC_SAFER_TAB_C
 
 
 /* This is the box defined by ebox[x] = 45^x mod 257.
 /* This is the box defined by ebox[x] = 45^x mod 257.
  * Its assumed that the value "256" corresponds to zero. */
  * Its assumed that the value "256" corresponds to zero. */
@@ -55,10 +49,6 @@ static const unsigned char safer_lbox[256] = {
 184,  64, 120,  45,  58, 233, 100,  31, 146, 144, 125,  57, 111, 224, 137,  48
 184,  64, 120,  45,  58, 233, 100,  31, 146, 144, 125,  57, 111, 224, 137,  48
 };
 };
 
 
-#endif /* __LTC_SAFER_TAB_C__ */
+#endif /* LTC_SAFER_TAB_C */
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 19 - 21
libtomcrypt.mod/libtomcrypt/src/ciphers/safer/saferp.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
    @file saferp.c
    @file saferp.c
@@ -15,7 +9,7 @@
 
 
 #ifdef LTC_SAFERP
 #ifdef LTC_SAFERP
 
 
-#define __LTC_SAFER_TAB_C__
+#define LTC_SAFER_TAB_C
 #include "safer_tab.c"
 #include "safer_tab.c"
 
 
 const struct ltc_cipher_descriptor saferp_desc =
 const struct ltc_cipher_descriptor saferp_desc =
@@ -143,37 +137,37 @@ const struct ltc_cipher_descriptor saferp_desc =
 
 
 #ifdef LTC_SMALL_CODE
 #ifdef LTC_SMALL_CODE
 
 
-static void _round(unsigned char *b, int i, const symmetric_key *skey)
+static void s_round(unsigned char *b, int i, const symmetric_key *skey)
 {
 {
    ROUND(b, i);
    ROUND(b, i);
 }
 }
 
 
-static void _iround(unsigned char *b, int i, const symmetric_key *skey)
+static void s_iround(unsigned char *b, int i, const symmetric_key *skey)
 {
 {
    iROUND(b, i);
    iROUND(b, i);
 }
 }
 
 
-static void _lt(unsigned char *b, unsigned char *b2)
+static void s_lt(unsigned char *b, unsigned char *b2)
 {
 {
    LT(b, b2);
    LT(b, b2);
 }
 }
 
 
-static void _ilt(unsigned char *b, unsigned char *b2)
+static void s_ilt(unsigned char *b, unsigned char *b2)
 {
 {
    iLT(b, b2);
    iLT(b, b2);
 }
 }
 
 
 #undef ROUND
 #undef ROUND
-#define ROUND(b, i) _round(b, i, skey)
+#define ROUND(b, i) s_round(b, i, skey)
 
 
 #undef iROUND
 #undef iROUND
-#define iROUND(b, i) _iround(b, i, skey)
+#define iROUND(b, i) s_iround(b, i, skey)
 
 
 #undef LT
 #undef LT
-#define LT(b, b2) _lt(b, b2)
+#define LT(b, b2) s_lt(b, b2)
 
 
 #undef iLT
 #undef iLT
-#define iLT(b, b2) _ilt(b, b2)
+#define iLT(b, b2) s_ilt(b, b2)
 
 
 #endif
 #endif
 
 
@@ -347,6 +341,10 @@ int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetr
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
 
 
+   if (skey->saferp.rounds < 8 || skey->saferp.rounds > 16) {
+       return CRYPT_INVALID_ROUNDS;
+   }
+
    /* do eight rounds */
    /* do eight rounds */
    for (x = 0; x < 16; x++) {
    for (x = 0; x < 16; x++) {
        b[x] = pt[x];
        b[x] = pt[x];
@@ -411,6 +409,10 @@ int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetr
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(skey != NULL);
 
 
+   if (skey->saferp.rounds < 8 || skey->saferp.rounds > 16) {
+       return CRYPT_INVALID_ROUNDS;
+   }
+
    /* do eight rounds */
    /* do eight rounds */
    b[0] = ct[0] ^ skey->saferp.K[skey->saferp.rounds*2][0];
    b[0] = ct[0] ^ skey->saferp.K[skey->saferp.rounds*2][0];
    b[1] = (ct[1] - skey->saferp.K[skey->saferp.rounds*2][1]) & 255;
    b[1] = (ct[1] - skey->saferp.K[skey->saferp.rounds*2][1]) & 255;
@@ -563,7 +565,3 @@ int saferp_keysize(int *keysize)
 #endif
 #endif
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 76 - 86
libtomcrypt.mod/libtomcrypt/src/ciphers/serpent.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /* Based on serpent.cpp - originally written and placed in the public domain by Wei Dai
 /* Based on serpent.cpp - originally written and placed in the public domain by Wei Dai
    https://github.com/weidai11/cryptopp/blob/master/serpent.cpp
    https://github.com/weidai11/cryptopp/blob/master/serpent.cpp
@@ -33,7 +27,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
 };
 };
 
 
 /* linear transformation */
 /* linear transformation */
-#define _LT(i,a,b,c,d,e)  {                                 \
+#define s_lt(i,a,b,c,d,e)  {                                 \
                             a = ROLc(a, 13);                \
                             a = ROLc(a, 13);                \
                             c = ROLc(c, 3);                 \
                             c = ROLc(c, 3);                 \
                             d = ROLc(d ^ c ^ (a << 3), 7);  \
                             d = ROLc(d ^ c ^ (a << 3), 7);  \
@@ -43,7 +37,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
                           }
                           }
 
 
 /* inverse linear transformation */
 /* inverse linear transformation */
-#define _ILT(i,a,b,c,d,e) {                                 \
+#define s_ilt(i,a,b,c,d,e) {                                 \
                             c = RORc(c, 22);                \
                             c = RORc(c, 22);                \
                             a = RORc(a, 5);                 \
                             a = RORc(a, 5);                 \
                             c ^= d ^ (b << 7);              \
                             c ^= d ^ (b << 7);              \
@@ -56,32 +50,32 @@ const struct ltc_cipher_descriptor serpent_desc = {
                           }
                           }
 
 
 /* order of output from S-box functions */
 /* order of output from S-box functions */
-#define _beforeS0(f) f(0,a,b,c,d,e)
-#define _afterS0(f)  f(1,b,e,c,a,d)
-#define _afterS1(f)  f(2,c,b,a,e,d)
-#define _afterS2(f)  f(3,a,e,b,d,c)
-#define _afterS3(f)  f(4,e,b,d,c,a)
-#define _afterS4(f)  f(5,b,a,e,c,d)
-#define _afterS5(f)  f(6,a,c,b,e,d)
-#define _afterS6(f)  f(7,a,c,d,b,e)
-#define _afterS7(f)  f(8,d,e,b,a,c)
+#define s_beforeS0(f) f(0,a,b,c,d,e)
+#define s_afterS0(f)  f(1,b,e,c,a,d)
+#define s_afterS1(f)  f(2,c,b,a,e,d)
+#define s_afterS2(f)  f(3,a,e,b,d,c)
+#define s_afterS3(f)  f(4,e,b,d,c,a)
+#define s_afterS4(f)  f(5,b,a,e,c,d)
+#define s_afterS5(f)  f(6,a,c,b,e,d)
+#define s_afterS6(f)  f(7,a,c,d,b,e)
+#define s_afterS7(f)  f(8,d,e,b,a,c)
 
 
 /* order of output from inverse S-box functions */
 /* order of output from inverse S-box functions */
-#define _beforeI7(f) f(8,a,b,c,d,e)
-#define _afterI7(f)  f(7,d,a,b,e,c)
-#define _afterI6(f)  f(6,a,b,c,e,d)
-#define _afterI5(f)  f(5,b,d,e,c,a)
-#define _afterI4(f)  f(4,b,c,e,a,d)
-#define _afterI3(f)  f(3,a,b,e,c,d)
-#define _afterI2(f)  f(2,b,d,e,c,a)
-#define _afterI1(f)  f(1,a,b,c,e,d)
-#define _afterI0(f)  f(0,a,d,b,e,c)
+#define s_beforeI7(f) f(8,a,b,c,d,e)
+#define s_afterI7(f)  f(7,d,a,b,e,c)
+#define s_afterI6(f)  f(6,a,b,c,e,d)
+#define s_afterI5(f)  f(5,b,d,e,c,a)
+#define s_afterI4(f)  f(4,b,c,e,a,d)
+#define s_afterI3(f)  f(3,a,b,e,c,d)
+#define s_afterI2(f)  f(2,b,d,e,c,a)
+#define s_afterI1(f)  f(1,a,b,c,e,d)
+#define s_afterI0(f)  f(0,a,d,b,e,c)
 
 
 /* The instruction sequences for the S-box functions
 /* The instruction sequences for the S-box functions
  * come from Dag Arne Osvik's paper "Speeding up Serpent".
  * come from Dag Arne Osvik's paper "Speeding up Serpent".
  */
  */
 
 
-#define _S0(i, r0, r1, r2, r3, r4) { \
+#define s_s0(i, r0, r1, r2, r3, r4) { \
    r3 ^= r0;   \
    r3 ^= r0;   \
    r4 = r1;    \
    r4 = r1;    \
    r1 &= r3;   \
    r1 &= r3;   \
@@ -102,7 +96,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 ^= r3;   \
    r4 ^= r3;   \
 }
 }
 
 
-#define _I0(i, r0, r1, r2, r3, r4) { \
+#define s_i0(i, r0, r1, r2, r3, r4) { \
    r2 = ~r2;   \
    r2 = ~r2;   \
    r4 = r1;    \
    r4 = r1;    \
    r1 |= r0;   \
    r1 |= r0;   \
@@ -124,7 +118,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 ^= r2;   \
    r4 ^= r2;   \
 }
 }
 
 
-#define _S1(i, r0, r1, r2, r3, r4) { \
+#define s_s1(i, r0, r1, r2, r3, r4) { \
    r0 = ~r0;   \
    r0 = ~r0;   \
    r2 = ~r2;   \
    r2 = ~r2;   \
    r4 = r0;    \
    r4 = r0;    \
@@ -145,7 +139,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r0 ^= r4;   \
    r0 ^= r4;   \
 }
 }
 
 
-#define _I1(i, r0, r1, r2, r3, r4) { \
+#define s_i1(i, r0, r1, r2, r3, r4) { \
    r4 = r1;    \
    r4 = r1;    \
    r1 ^= r3;   \
    r1 ^= r3;   \
    r3 &= r1;   \
    r3 &= r1;   \
@@ -167,7 +161,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r3 ^= r1;   \
    r3 ^= r1;   \
 }
 }
 
 
-#define _S2(i, r0, r1, r2, r3, r4) { \
+#define s_s2(i, r0, r1, r2, r3, r4) { \
    r4 = r0;    \
    r4 = r0;    \
    r0 &= r2;   \
    r0 &= r2;   \
    r0 ^= r3;   \
    r0 ^= r3;   \
@@ -186,7 +180,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 = ~r4;   \
    r4 = ~r4;   \
 }
 }
 
 
-#define _I2(i, r0, r1, r2, r3, r4) { \
+#define s_i2(i, r0, r1, r2, r3, r4) { \
    r2 ^= r3;   \
    r2 ^= r3;   \
    r3 ^= r0;   \
    r3 ^= r0;   \
    r4 = r3;    \
    r4 = r3;    \
@@ -208,7 +202,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r3 ^= r0;   \
    r3 ^= r0;   \
 }
 }
 
 
-#define _S3(i, r0, r1, r2, r3, r4) { \
+#define s_s3(i, r0, r1, r2, r3, r4) { \
    r4 = r0;    \
    r4 = r0;    \
    r0 |= r3;   \
    r0 |= r3;   \
    r3 ^= r1;   \
    r3 ^= r1;   \
@@ -230,7 +224,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r1 ^= r0;   \
    r1 ^= r0;   \
 }
 }
 
 
-#define _I3(i, r0, r1, r2, r3, r4) { \
+#define s_i3(i, r0, r1, r2, r3, r4) { \
    r4 = r2;    \
    r4 = r2;    \
    r2 ^= r1;   \
    r2 ^= r1;   \
    r1 &= r2;   \
    r1 &= r2;   \
@@ -251,7 +245,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r2 ^= r4;   \
    r2 ^= r4;   \
 }
 }
 
 
-#define _S4(i, r0, r1, r2, r3, r4) { \
+#define s_s4(i, r0, r1, r2, r3, r4) { \
    r1 ^= r3;   \
    r1 ^= r3;   \
    r3 = ~r3;   \
    r3 = ~r3;   \
    r2 ^= r3;   \
    r2 ^= r3;   \
@@ -274,7 +268,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 ^= r2;   \
    r4 ^= r2;   \
 }
 }
 
 
-#define _I4(i, r0, r1, r2, r3, r4) { \
+#define s_i4(i, r0, r1, r2, r3, r4) { \
    r4 = r2;    \
    r4 = r2;    \
    r2 &= r3;   \
    r2 &= r3;   \
    r2 ^= r1;   \
    r2 ^= r1;   \
@@ -297,7 +291,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r2 ^= r1;   \
    r2 ^= r1;   \
 }
 }
 
 
-#define _S5(i, r0, r1, r2, r3, r4) { \
+#define s_s5(i, r0, r1, r2, r3, r4) { \
    r0 ^= r1;   \
    r0 ^= r1;   \
    r1 ^= r3;   \
    r1 ^= r3;   \
    r3 = ~r3;   \
    r3 = ~r3;   \
@@ -319,7 +313,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r2 ^= r4;   \
    r2 ^= r4;   \
 }
 }
 
 
-#define _I5(i, r0, r1, r2, r3, r4) { \
+#define s_i5(i, r0, r1, r2, r3, r4) { \
    r1 = ~r1;   \
    r1 = ~r1;   \
    r4 = r3;    \
    r4 = r3;    \
    r2 ^= r1;   \
    r2 ^= r1;   \
@@ -341,7 +335,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 = ~r4;   \
    r4 = ~r4;   \
 }
 }
 
 
-#define _S6(i, r0, r1, r2, r3, r4) { \
+#define s_s6(i, r0, r1, r2, r3, r4) { \
    r2 = ~r2;   \
    r2 = ~r2;   \
    r4 = r3;    \
    r4 = r3;    \
    r3 &= r0;   \
    r3 &= r0;   \
@@ -362,7 +356,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r2 ^= r3;   \
    r2 ^= r3;   \
 }
 }
 
 
-#define _I6(i, r0, r1, r2, r3, r4) { \
+#define s_i6(i, r0, r1, r2, r3, r4) { \
    r0 ^= r2;   \
    r0 ^= r2;   \
    r4 = r2;    \
    r4 = r2;    \
    r2 &= r0;   \
    r2 &= r0;   \
@@ -382,7 +376,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 ^= r0;   \
    r4 ^= r0;   \
 }
 }
 
 
-#define _S7(i, r0, r1, r2, r3, r4) { \
+#define s_s7(i, r0, r1, r2, r3, r4) { \
    r4 = r2;    \
    r4 = r2;    \
    r2 &= r1;   \
    r2 &= r1;   \
    r2 ^= r3;   \
    r2 ^= r3;   \
@@ -405,7 +399,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    r4 ^= r1;   \
    r4 ^= r1;   \
 }
 }
 
 
-#define _I7(i, r0, r1, r2, r3, r4) { \
+#define s_i7(i, r0, r1, r2, r3, r4) { \
    r4 = r2;    \
    r4 = r2;    \
    r2 ^= r0;   \
    r2 ^= r0;   \
    r0 &= r3;   \
    r0 &= r3;   \
@@ -428,28 +422,28 @@ const struct ltc_cipher_descriptor serpent_desc = {
 }
 }
 
 
 /* key xor */
 /* key xor */
-#define _KX(r, a, b, c, d, e) { \
+#define s_kx(r, a, b, c, d, e) { \
    a ^= k[4 * r + 0];   \
    a ^= k[4 * r + 0];   \
    b ^= k[4 * r + 1];   \
    b ^= k[4 * r + 1];   \
    c ^= k[4 * r + 2];   \
    c ^= k[4 * r + 2];   \
    d ^= k[4 * r + 3];   \
    d ^= k[4 * r + 3];   \
 }
 }
 
 
-#define _LK(r, a, b, c, d, e) { \
+#define s_lk(r, a, b, c, d, e) { \
    a = k[(8-r)*4 + 0];  \
    a = k[(8-r)*4 + 0];  \
    b = k[(8-r)*4 + 1];  \
    b = k[(8-r)*4 + 1];  \
    c = k[(8-r)*4 + 2];  \
    c = k[(8-r)*4 + 2];  \
    d = k[(8-r)*4 + 3];  \
    d = k[(8-r)*4 + 3];  \
 }
 }
 
 
-#define _SK(r, a, b, c, d, e) { \
+#define s_sk(r, a, b, c, d, e) { \
    k[(8-r)*4 + 4] = a;  \
    k[(8-r)*4 + 4] = a;  \
    k[(8-r)*4 + 5] = b;  \
    k[(8-r)*4 + 5] = b;  \
    k[(8-r)*4 + 6] = c;  \
    k[(8-r)*4 + 6] = c;  \
    k[(8-r)*4 + 7] = d;  \
    k[(8-r)*4 + 7] = d;  \
 }
 }
 
 
-static int _setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
+static int s_setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
 {
 {
    int i;
    int i;
    ulong32 t;
    ulong32 t;
@@ -473,22 +467,22 @@ static int _setup_key(const unsigned char *key, int keylen, int rounds, ulong32
    k -= 20;
    k -= 20;
 
 
    for (i = 0; i < rounds/8; i++) {
    for (i = 0; i < rounds/8; i++) {
-      _afterS2(_LK);  _afterS2(_S3);  _afterS3(_SK);
-      _afterS1(_LK);  _afterS1(_S2);  _afterS2(_SK);
-      _afterS0(_LK);  _afterS0(_S1);  _afterS1(_SK);
-      _beforeS0(_LK); _beforeS0(_S0); _afterS0(_SK);
+      s_afterS2(s_lk);  s_afterS2(s_s3);  s_afterS3(s_sk);
+      s_afterS1(s_lk);  s_afterS1(s_s2);  s_afterS2(s_sk);
+      s_afterS0(s_lk);  s_afterS0(s_s1);  s_afterS1(s_sk);
+      s_beforeS0(s_lk); s_beforeS0(s_s0); s_afterS0(s_sk);
       k += 8*4;
       k += 8*4;
-      _afterS6(_LK); _afterS6(_S7); _afterS7(_SK);
-      _afterS5(_LK); _afterS5(_S6); _afterS6(_SK);
-      _afterS4(_LK); _afterS4(_S5); _afterS5(_SK);
-      _afterS3(_LK); _afterS3(_S4); _afterS4(_SK);
+      s_afterS6(s_lk); s_afterS6(s_s7); s_afterS7(s_sk);
+      s_afterS5(s_lk); s_afterS5(s_s6); s_afterS6(s_sk);
+      s_afterS4(s_lk); s_afterS4(s_s5); s_afterS5(s_sk);
+      s_afterS3(s_lk); s_afterS3(s_s4); s_afterS4(s_sk);
    }
    }
-   _afterS2(_LK); _afterS2(_S3); _afterS3(_SK);
+   s_afterS2(s_lk); s_afterS2(s_s3); s_afterS3(s_sk);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
+static int s_enc_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
 {
 {
    ulong32 a, b, c, d, e;
    ulong32 a, b, c, d, e;
    unsigned int i = 1;
    unsigned int i = 1;
@@ -499,14 +493,14 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
    LOAD32L(d, in + 12);
    LOAD32L(d, in + 12);
 
 
    do {
    do {
-      _beforeS0(_KX); _beforeS0(_S0); _afterS0(_LT);
-      _afterS0(_KX);  _afterS0(_S1);  _afterS1(_LT);
-      _afterS1(_KX);  _afterS1(_S2);  _afterS2(_LT);
-      _afterS2(_KX);  _afterS2(_S3);  _afterS3(_LT);
-      _afterS3(_KX);  _afterS3(_S4);  _afterS4(_LT);
-      _afterS4(_KX);  _afterS4(_S5);  _afterS5(_LT);
-      _afterS5(_KX);  _afterS5(_S6);  _afterS6(_LT);
-      _afterS6(_KX);  _afterS6(_S7);
+      s_beforeS0(s_kx); s_beforeS0(s_s0); s_afterS0(s_lt);
+       s_afterS0(s_kx);  s_afterS0(s_s1); s_afterS1(s_lt);
+       s_afterS1(s_kx);  s_afterS1(s_s2); s_afterS2(s_lt);
+       s_afterS2(s_kx);  s_afterS2(s_s3); s_afterS3(s_lt);
+       s_afterS3(s_kx);  s_afterS3(s_s4); s_afterS4(s_lt);
+       s_afterS4(s_kx);  s_afterS4(s_s5); s_afterS5(s_lt);
+       s_afterS5(s_kx);  s_afterS5(s_s6); s_afterS6(s_lt);
+       s_afterS6(s_kx);  s_afterS6(s_s7);
 
 
       if (i == 4) break;
       if (i == 4) break;
 
 
@@ -517,10 +511,10 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
       d = a;
       d = a;
       a = e;
       a = e;
       k += 32;
       k += 32;
-      _beforeS0(_LT);
+      s_beforeS0(s_lt);
    } while (1);
    } while (1);
 
 
-   _afterS7(_KX);
+   s_afterS7(s_kx);
 
 
    STORE32L(d, out + 0);
    STORE32L(d, out + 0);
    STORE32L(e, out + 4);
    STORE32L(e, out + 4);
@@ -530,7 +524,7 @@ static int _enc_block(const unsigned char *in, unsigned char *out, const ulong32
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
+static int s_dec_block(const unsigned char *in, unsigned char *out, const ulong32 *k)
 {
 {
    ulong32 a, b, c, d, e;
    ulong32 a, b, c, d, e;
    unsigned int i;
    unsigned int i;
@@ -543,7 +537,7 @@ static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32
    i = 4;
    i = 4;
    k += 96;
    k += 96;
 
 
-   _beforeI7(_KX);
+   s_beforeI7(s_kx);
    goto start;
    goto start;
 
 
    do {
    do {
@@ -551,16 +545,16 @@ static int _dec_block(const unsigned char *in, unsigned char *out, const ulong32
       b = d;
       b = d;
       d = e;
       d = e;
       k -= 32;
       k -= 32;
-      _beforeI7(_ILT);
+      s_beforeI7(s_ilt);
 start:
 start:
-                      _beforeI7(_I7); _afterI7(_KX);
-      _afterI7(_ILT); _afterI7(_I6);  _afterI6(_KX);
-      _afterI6(_ILT); _afterI6(_I5);  _afterI5(_KX);
-      _afterI5(_ILT); _afterI5(_I4);  _afterI4(_KX);
-      _afterI4(_ILT); _afterI4(_I3);  _afterI3(_KX);
-      _afterI3(_ILT); _afterI3(_I2);  _afterI2(_KX);
-      _afterI2(_ILT); _afterI2(_I1);  _afterI1(_KX);
-      _afterI1(_ILT); _afterI1(_I0);  _afterI0(_KX);
+                      s_beforeI7(s_i7); s_afterI7(s_kx);
+      s_afterI7(s_ilt); s_afterI7(s_i6); s_afterI6(s_kx);
+      s_afterI6(s_ilt); s_afterI6(s_i5); s_afterI5(s_kx);
+      s_afterI5(s_ilt); s_afterI5(s_i4); s_afterI4(s_kx);
+      s_afterI4(s_ilt); s_afterI4(s_i3); s_afterI3(s_kx);
+      s_afterI3(s_ilt); s_afterI3(s_i2); s_afterI2(s_kx);
+      s_afterI2(s_ilt); s_afterI2(s_i1); s_afterI1(s_kx);
+      s_afterI1(s_ilt); s_afterI1(s_i0); s_afterI0(s_kx);
    } while (--i != 0);
    } while (--i != 0);
 
 
    STORE32L(a, out + 0);
    STORE32L(a, out + 0);
@@ -581,7 +575,7 @@ int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
    if (num_rounds != 0 && num_rounds != 32) return CRYPT_INVALID_ROUNDS;
    if (num_rounds != 0 && num_rounds != 32) return CRYPT_INVALID_ROUNDS;
    if (keylen != 16 && keylen != 24 && keylen != 32) return CRYPT_INVALID_KEYSIZE;
    if (keylen != 16 && keylen != 24 && keylen != 32) return CRYPT_INVALID_KEYSIZE;
 
 
-   err = _setup_key(key, keylen, 32, skey->serpent.k);
+   err = s_setup_key(key, keylen, 32, skey->serpent.k);
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    burn_stack(sizeof(ulong32) * 14 + sizeof(int));
    burn_stack(sizeof(ulong32) * 14 + sizeof(int));
 #endif
 #endif
@@ -590,7 +584,7 @@ int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
 
 
 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _enc_block(pt, ct, skey->serpent.k);
+   int err = s_enc_block(pt, ct, skey->serpent.k);
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
 #endif
 #endif
@@ -599,7 +593,7 @@ int serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
 
 
 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _dec_block(ct, pt, skey->serpent.k);
+   int err = s_dec_block(ct, pt, skey->serpent.k);
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
 #endif
 #endif
@@ -721,7 +715,3 @@ int serpent_test(void)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 6 - 16
libtomcrypt.mod/libtomcrypt/src/ciphers/skipjack.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file skipjack.c
   @file skipjack.c
@@ -139,7 +133,7 @@ static unsigned ig_func(unsigned w, int *kp, const unsigned char *key)
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -189,7 +183,7 @@ int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _skipjack_ecb_encrypt(pt, ct, skey);
+   int err = s_skipjack_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
    burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
    return err;
    return err;
 }
 }
@@ -203,7 +197,7 @@ int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symme
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -257,7 +251,7 @@ int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err = _skipjack_ecb_decrypt(ct, pt, skey);
+   int err = s_skipjack_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
    burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
    return err;
    return err;
 }
 }
@@ -338,7 +332,3 @@ int skipjack_keysize(int *keysize)
 }
 }
 
 
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 209 - 0
libtomcrypt.mod/libtomcrypt/src/ciphers/tea.c

@@ -0,0 +1,209 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+
+/**
+  @file tea.c
+  Implementation of TEA, Steffen Jaeckel
+*/
+#include "tomcrypt_private.h"
+
+#ifdef LTC_TEA
+
+const struct ltc_cipher_descriptor tea_desc =
+{
+    "tea",
+    26,
+    16, 16, 8, 32,
+    &tea_setup,
+    &tea_ecb_encrypt,
+    &tea_ecb_decrypt,
+    &tea_test,
+    &tea_done,
+    &tea_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+#define DELTA 0x9E3779B9uL
+#define SUM 0xC6EF3720uL
+
+int tea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+{
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   /* check arguments */
+   if (keylen != 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+
+   if (num_rounds != 0 && num_rounds != 32) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
+   /* load key */
+   LOAD32H(skey->tea.k[0], key+0);
+   LOAD32H(skey->tea.k[1], key+4);
+   LOAD32H(skey->tea.k[2], key+8);
+   LOAD32H(skey->tea.k[3], key+12);
+
+   return CRYPT_OK;
+}
+
+/**
+  Encrypts a block of text with TEA
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+  @return CRYPT_OK if successful
+*/
+int tea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+{
+   ulong32 y, z, sum = 0;
+   const ulong32 delta = DELTA;
+   int r;
+
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32H(y, &pt[0]);
+   LOAD32H(z, &pt[4]);
+   for (r = 0; r < 32; r++) {
+      sum += delta;
+      y += ((z<<4) + skey->tea.k[0]) ^ (z + sum) ^ ((z>>5) + skey->tea.k[1]);
+      z += ((y<<4) + skey->tea.k[2]) ^ (y + sum) ^ ((y>>5) + skey->tea.k[3]);
+   }
+   STORE32H(y, &ct[0]);
+   STORE32H(z, &ct[4]);
+   return CRYPT_OK;
+}
+
+/**
+  Decrypts a block of text with TEA
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled
+  @return CRYPT_OK if successful
+*/
+int tea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+{
+   ulong32 v0, v1, sum = SUM;
+   const ulong32 delta = DELTA;
+   int r;
+
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32H(v0, &ct[0]);
+   LOAD32H(v1, &ct[4]);
+
+   for (r = 0; r < 32; r++) {
+      v1 -= ((v0 << 4) + skey->tea.k[2]) ^ (v0 + sum) ^ ((v0 >> 5) + skey->tea.k[3]);
+      v0 -= ((v1 << 4) + skey->tea.k[0]) ^ (v1 + sum) ^ ((v1 >> 5) + skey->tea.k[1]);
+      sum -= delta;
+   }
+
+   STORE32H(v0, &pt[0]);
+   STORE32H(v1, &pt[4]);
+   return CRYPT_OK;
+}
+
+/**
+  Performs a self-test of the TEA block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
+int tea_test(void)
+{
+ #ifndef LTC_TEST
+    return CRYPT_NOP;
+ #else
+    static const struct {
+        const char *key, *pt, *ct;
+    } tests[] = {
+       {
+         "00000000000000000000000000000000",
+         "0000000000000000",
+         "41ea3a0a94baa940"
+       }, {
+         "32a1e65408b63bb9214105744ec5d2e2",
+         "5ada1d89a9c3801a",
+         "dd46249e28aa0b4b"
+       }, {
+         "60388adadf70a1f5d9cb4e097d2c6c57",
+         "7a6adb4d69c53e0f",
+         "44b71215cf25368a"
+       }, {
+         "4368d2249bd0321eb7c56d5b63a1bfac",
+         "5a5d7ca2e186c41a",
+         "91f56dff7281794f"
+       }, {
+         "5c60bff27072d01c4513c5eb8f3a38ab",
+         "80d9c4adcf899635",
+         "2bb0f1b3c023ed11"
+       }
+    };
+   unsigned char ptct[2][8];
+   unsigned char tmp[2][8];
+   unsigned char key[16];
+   unsigned long l;
+   symmetric_key skey;
+   size_t i;
+   int err, y;
+   for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
+       zeromem(&skey, sizeof(skey));
+
+       l = sizeof(key);
+       if ((err = base16_decode(tests[i].key, XSTRLEN(tests[i].key), key, &l)) != CRYPT_OK) return err;
+       l = sizeof(ptct[0]);
+       if ((err = base16_decode(tests[i].pt, XSTRLEN(tests[i].pt), ptct[0], &l)) != CRYPT_OK) return err;
+       l = sizeof(ptct[1]);
+       if ((err = base16_decode(tests[i].ct, XSTRLEN(tests[i].ct), ptct[1], &l)) != CRYPT_OK) return err;
+
+       if ((err = tea_setup(key, 16, 0, &skey)) != CRYPT_OK)  {
+          return err;
+       }
+       tea_ecb_encrypt(ptct[0], tmp[0], &skey);
+       tea_ecb_decrypt(tmp[0], tmp[1], &skey);
+
+       if (compare_testvector(tmp[0], 8, ptct[1], 8, "TEA Encrypt", i) != 0 ||
+             compare_testvector(tmp[1], 8, ptct[0], 8, "TEA Decrypt", i) != 0) {
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+      /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
+      for (y = 0; y < 8; y++) tmp[0][y] = 0;
+      for (y = 0; y < 1000; y++) tea_ecb_encrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 1000; y++) tea_ecb_decrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
+   } /* for */
+
+   return CRYPT_OK;
+ #endif
+}
+
+/** Terminate the context
+   @param skey    The scheduled key
+*/
+void tea_done(symmetric_key *skey)
+{
+  LTC_UNUSED_PARAM(skey);
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int tea_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+   *keysize = 16;
+   return CRYPT_OK;
+}
+
+#endif
+

+ 13 - 23
libtomcrypt.mod/libtomcrypt/src/ciphers/twofish/twofish.c

@@ -1,11 +1,5 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
  /**
  /**
    @file twofish.c
    @file twofish.c
@@ -64,7 +58,7 @@ static const unsigned char qord[4][5] = {
 
 
 #ifdef LTC_TWOFISH_TABLES
 #ifdef LTC_TWOFISH_TABLES
 
 
-#define __LTC_TWOFISH_TAB_C__
+#define LTC_TWOFISH_TAB_C
 #include "twofish_tab.c"
 #include "twofish_tab.c"
 
 
 #define sbox(i, x) ((ulong32)SBOX[i][(x)&255])
 #define sbox(i, x) ((ulong32)SBOX[i][(x)&255])
@@ -89,7 +83,7 @@ static const unsigned char qbox[2][4][16] = {
 
 
 /* computes S_i[x] */
 /* computes S_i[x] */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static ulong32 _sbox(int i, ulong32 x)
+static ulong32 s_sbox(int i, ulong32 x)
 #else
 #else
 static ulong32 sbox(int i, ulong32 x)
 static ulong32 sbox(int i, ulong32 x)
 #endif
 #endif
@@ -131,7 +125,7 @@ static ulong32 sbox(int i, ulong32 x)
 static ulong32 sbox(int i, ulong32 x)
 static ulong32 sbox(int i, ulong32 x)
 {
 {
    ulong32 y;
    ulong32 y;
-   y = _sbox(i, x);
+   y = s_sbox(i, x);
    burn_stack(sizeof(unsigned char) * 11);
    burn_stack(sizeof(unsigned char) * 11);
    return y;
    return y;
 }
 }
@@ -288,7 +282,7 @@ static void h_func(const unsigned char *in, unsigned char *out, const unsigned c
 #else
 #else
 
 
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static ulong32 _g_func(ulong32 x, const symmetric_key *key)
+static ulong32 s_g_func(ulong32 x, const symmetric_key *key)
 #else
 #else
 static ulong32 g_func(ulong32 x, const symmetric_key *key)
 static ulong32 g_func(ulong32 x, const symmetric_key *key)
 #endif
 #endif
@@ -324,7 +318,7 @@ static ulong32 g_func(ulong32 x, const symmetric_key *key)
 static ulong32 g_func(ulong32 x, const symmetric_key *key)
 static ulong32 g_func(ulong32 x, const symmetric_key *key)
 {
 {
     ulong32 y;
     ulong32 y;
-    y = _g_func(x, key);
+    y = s_g_func(x, key);
     burn_stack(sizeof(unsigned char) * 4 + sizeof(ulong32));
     burn_stack(sizeof(unsigned char) * 4 + sizeof(ulong32));
     return y;
     return y;
 }
 }
@@ -341,7 +335,7 @@ static ulong32 g_func(ulong32 x, const symmetric_key *key)
     @return CRYPT_OK if successful
     @return CRYPT_OK if successful
  */
  */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+static int s_twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 #else
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #endif
 #endif
@@ -454,7 +448,7 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
 {
    int x;
    int x;
-   x = _twofish_setup(key, keylen, num_rounds, skey);
+   x = s_twofish_setup(key, keylen, num_rounds, skey);
    burn_stack(sizeof(int) * 7 + sizeof(unsigned char) * 56 + sizeof(ulong32) * 2);
    burn_stack(sizeof(int) * 7 + sizeof(unsigned char) * 56 + sizeof(ulong32) * 2);
    return x;
    return x;
 }
 }
@@ -468,7 +462,7 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
+static int s_twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #else
 #else
 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 #endif
 #endif
@@ -528,7 +522,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
 {
 {
-   int err = _twofish_ecb_encrypt(pt, ct, skey);
+   int err = s_twofish_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -542,7 +536,7 @@ int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmet
   @return CRYPT_OK if successful
   @return CRYPT_OK if successful
 */
 */
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
+static int s_twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #else
 #else
 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 #endif
 #endif
@@ -604,7 +598,7 @@ int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmet
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
 {
 {
-   int err =_twofish_ecb_decrypt(ct, pt, skey);
+   int err = s_twofish_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
    return err;
    return err;
 }
 }
@@ -710,7 +704,3 @@ int twofish_keysize(int *keysize)
 
 
 #endif
 #endif
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 4 - 14
libtomcrypt.mod/libtomcrypt/src/ciphers/twofish/twofish_tab.c

@@ -1,18 +1,12 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
  /**
  /**
     @file twofish_tab.c
     @file twofish_tab.c
     Twofish tables, Tom St Denis
     Twofish tables, Tom St Denis
  */
  */
 #ifdef LTC_TWOFISH_TABLES
 #ifdef LTC_TWOFISH_TABLES
-#ifdef __LTC_TWOFISH_TAB_C__
+#ifdef LTC_TWOFISH_TAB_C
 
 
 /* pre generated 8x8 tables from the four 4x4s */
 /* pre generated 8x8 tables from the four 4x4s */
 static const unsigned char SBOX[2][256] = {
 static const unsigned char SBOX[2][256] = {
@@ -488,9 +482,5 @@ static const ulong32 rs_tab7[256] = {
 
 
 #endif /* LTC_TWOFISH_ALL_TABLES */
 #endif /* LTC_TWOFISH_ALL_TABLES */
 
 
-#endif /* __LTC_TWOFISH_TAB_C__ */
+#endif /* LTC_TWOFISH_TAB_C */
 #endif
 #endif
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 3 - 13
libtomcrypt.mod/libtomcrypt/src/ciphers/xtea.c

@@ -1,15 +1,9 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 
 /**
 /**
   @file xtea.c
   @file xtea.c
-  Implementation of LTC_XTEA, Tom St Denis
+  Implementation of eXtended TEA, Tom St Denis
 */
 */
 #include "tomcrypt_private.h"
 #include "tomcrypt_private.h"
 
 
@@ -255,7 +249,3 @@ int xtea_keysize(int *keysize)
 
 
 
 
 
 
-
-/* ref:         HEAD -> develop */
-/* git commit:  a1f6312416ef6cd183ee62db58b640dc2d7ec1f4 */
-/* commit time: 2019-09-04 13:44:47 +0200 */

+ 53 - 0
libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_add_aad.c

@@ -0,0 +1,53 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+#include "tomcrypt_private.h"
+
+#ifdef LTC_CCM_MODE
+
+/**
+  Add AAD to the CCM state
+  @param ccm       The CCM state
+  @param adata     The additional authentication data to add to the CCM state
+  @param adatalen  The length of the AAD data.
+  @return CRYPT_OK on success
+ */
+int ccm_add_aad(ccm_state *ccm,
+                const unsigned char *adata,  unsigned long adatalen)
+{
+   unsigned long y;
+   int            err;
+
+   LTC_ARGCHK(ccm   != NULL);
+   LTC_ARGCHK(adata != NULL);
+
+   if (ccm->aadlen < ccm->current_aadlen + adatalen) {
+      return CRYPT_INVALID_ARG;
+   }
+   ccm->current_aadlen += adatalen;
+
+   /* now add the data */
+   for (y = 0; y < adatalen; y++) {
+      if (ccm->x == 16) {
+         /* full block so let's encrypt it */
+         if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
+            return err;
+         }
+         ccm->x = 0;
+      }
+      ccm->PAD[ccm->x++] ^= adata[y];
+   }
+
+   /* remainder? */
+   if (ccm->aadlen == ccm->current_aadlen) {
+      if (ccm->x != 0) {
+         if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
+            return err;
+         }
+      }
+      ccm->x = 0;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif

+ 106 - 0
libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_add_nonce.c

@@ -0,0 +1,106 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+#include "tomcrypt_private.h"
+
+#ifdef LTC_CCM_MODE
+
+/**
+  Add nonce data to the CCM state
+  @param ccm       The CCM state
+  @param nonce     The nonce data to add
+  @param noncelen  The length of the nonce
+  @return CRYPT_OK on success
+ */
+int ccm_add_nonce(ccm_state *ccm,
+                  const unsigned char *nonce,     unsigned long noncelen)
+{
+   unsigned long x, y, len;
+   int           err;
+
+   LTC_ARGCHK(ccm   != NULL);
+   LTC_ARGCHK(nonce != NULL);
+
+   /* increase L to match the nonce len */
+   ccm->noncelen = (noncelen > 13) ? 13 : noncelen;
+   if ((15 - ccm->noncelen) > ccm->L) {
+      ccm->L = 15 - ccm->noncelen;
+   }
+   if (ccm->L > 8) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* decrease noncelen to match L */
+   if ((ccm->noncelen + ccm->L) > 15) {
+      ccm->noncelen = 15 - ccm->L;
+   }
+
+   /* form B_0 == flags | Nonce N | l(m) */
+   x = 0;
+   ccm->PAD[x++] = (unsigned char)(((ccm->aadlen > 0) ? (1<<6) : 0) |
+                   (((ccm->taglen - 2)>>1)<<3)        |
+                   (ccm->L-1));
+
+   /* nonce */
+   for (y = 0; y < 15 - ccm->L; y++) {
+      ccm->PAD[x++] = nonce[y];
+   }
+
+   /* store len */
+   len = ccm->ptlen;
+
+   /* shift len so the upper bytes of len are the contents of the length */
+   for (y = ccm->L; y < 4; y++) {
+      len <<= 8;
+   }
+
+   /* store l(m) (only store 32-bits) */
+   for (y = 0; ccm->L > 4 && (ccm->L-y)>4; y++) {
+      ccm->PAD[x++] = 0;
+   }
+   for (; y < ccm->L; y++) {
+      ccm->PAD[x++] = (unsigned char)((len >> 24) & 255);
+      len <<= 8;
+   }
+
+   /* encrypt PAD */
+   if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* handle header */
+   ccm->x = 0;
+   if (ccm->aadlen > 0) {
+      /* store length */
+      if (ccm->aadlen < ((1UL<<16) - (1UL<<8))) {
+         ccm->PAD[ccm->x++] ^= (ccm->aadlen>>8) & 255;
+         ccm->PAD[ccm->x++] ^= ccm->aadlen & 255;
+      } else {
+         ccm->PAD[ccm->x++] ^= 0xFF;
+         ccm->PAD[ccm->x++] ^= 0xFE;
+         ccm->PAD[ccm->x++] ^= (ccm->aadlen>>24) & 255;
+         ccm->PAD[ccm->x++] ^= (ccm->aadlen>>16) & 255;
+         ccm->PAD[ccm->x++] ^= (ccm->aadlen>>8) & 255;
+         ccm->PAD[ccm->x++] ^= ccm->aadlen & 255;
+      }
+   }
+
+   /* setup the ctr counter */
+   x = 0;
+
+   /* flags */
+   ccm->ctr[x++] = (unsigned char)ccm->L-1;
+
+   /* nonce */
+   for (y = 0; y < (16 - (ccm->L+1)); ++y) {
+      ccm->ctr[x++] = nonce[y];
+   }
+   /* offset */
+   while (x < 16) {
+      ccm->ctr[x++] = 0;
+   }
+
+   ccm->CTRlen = 16;
+   return CRYPT_OK;
+}
+
+#endif

+ 55 - 0
libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_done.c

@@ -0,0 +1,55 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+#include "tomcrypt_private.h"
+
+#ifdef LTC_CCM_MODE
+
+/**
+  Terminate a CCM stream
+  @param ccm     The CCM state
+  @param tag     [out] The destination for the MAC tag
+  @param taglen  [in/out]  The length of the MAC tag
+  @return CRYPT_OK on success
+ */
+int ccm_done(ccm_state *ccm,
+             unsigned char *tag,    unsigned long *taglen)
+{
+   unsigned long x, y;
+   int            err;
+
+   LTC_ARGCHK(ccm != NULL);
+
+   /* Check all data have been processed */
+   if (ccm->ptlen != ccm->current_ptlen) {
+      return CRYPT_ERROR;
+   }
+
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+   if (ccm->x != 0) {
+      if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->PAD, ccm->PAD, &ccm->K)) != CRYPT_OK) {
+         return err;
+      }
+   }
+
+   /* setup CTR for the TAG (zero the count) */
+   for (y = 15; y > 15 - ccm->L; y--) {
+      ccm->ctr[y] = 0x00;
+   }
+   if ((err = cipher_descriptor[ccm->cipher].ecb_encrypt(ccm->ctr, ccm->CTRPAD, &ccm->K)) != CRYPT_OK) {
+      return err;
+   }
+
+   cipher_descriptor[ccm->cipher].done(&ccm->K);
+
+   /* store the TAG */
+   for (x = 0; x < 16 && x < *taglen; x++) {
+      tag[x] = ccm->PAD[x] ^ ccm->CTRPAD[x];
+   }
+   *taglen = x;
+
+   return CRYPT_OK;
+}
+
+#endif

+ 64 - 0
libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_init.c

@@ -0,0 +1,64 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+#include "tomcrypt_private.h"
+
+#ifdef LTC_CCM_MODE
+
+/**
+  Initialize a CCM state
+  @param ccm     The CCM state to initialize
+  @param cipher  The index of the cipher to use
+  @param key     The secret key
+  @param keylen  The length of the secret key
+  @param ptlen   The length of the plain/cipher text that will be processed
+  @param taglen  The max length of the MAC tag
+  @param aadlen  The length of the AAD
+
+  @return CRYPT_OK on success
+ */
+int ccm_init(ccm_state *ccm, int cipher,
+             const unsigned char *key, int keylen, int ptlen, int taglen, int aadlen)
+{
+   int            err;
+
+   LTC_ARGCHK(ccm    != NULL);
+   LTC_ARGCHK(key    != NULL);
+
+   XMEMSET(ccm, 0, sizeof(ccm_state));
+
+   /* check cipher input */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   if (cipher_descriptor[cipher].block_length != 16) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* make sure the taglen is valid */
+   if (taglen < 4 || taglen > 16 || (taglen % 2) == 1 || aadlen < 0 || ptlen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+   ccm->taglen = taglen;
+
+   /* schedule key */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &ccm->K)) != CRYPT_OK) {
+      return err;
+   }
+   ccm->cipher = cipher;
+
+   /* let's get the L value */
+   ccm->ptlen = ptlen;
+   ccm->L   = 0;
+   while (ptlen) {
+      ++ccm->L;
+      ptlen >>= 8;
+   }
+   if (ccm->L <= 1) {
+      ccm->L = 2;
+   }
+
+   ccm->aadlen = aadlen;
+   return CRYPT_OK;
+}
+
+#endif

+ 372 - 0
libtomcrypt.mod/libtomcrypt/src/encauth/ccm/ccm_memory.c

@@ -0,0 +1,372 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+#include "tomcrypt_private.h"
+
+/**
+  @file ccm_memory.c
+  CCM support, process a block of memory, Tom St Denis
+*/
+
+#ifdef LTC_CCM_MODE
+
+/**
+   CCM encrypt/decrypt and produce an authentication tag
+
+     *1 'pt', 'ct' and 'tag' can both be 'in' or 'out', depending on 'direction'
+
+   @param cipher     The index of the cipher desired
+   @param key        The secret key to use
+   @param keylen     The length of the secret key (octets)
+   @param uskey      A previously scheduled key [optional can be NULL]
+   @param nonce      The session nonce [use once]
+   @param noncelen   The length of the nonce
+   @param header     The header for the session
+   @param headerlen  The length of the header (octets)
+   @param pt         [*1] The plaintext
+   @param ptlen      The length of the plaintext (octets)
+   @param ct         [*1] The ciphertext
+   @param tag        [*1] The destination tag
+   @param taglen     The max size and resulting size of the authentication tag
+   @param direction  Encrypt or Decrypt direction (0 or 1)
+   @return CRYPT_OK if successful
+*/
+int ccm_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    symmetric_key       *uskey,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+          unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen,
+                    int  direction)
+{
+   unsigned char  PAD[16], ctr[16], CTRPAD[16], ptTag[16], b, *pt_real;
+   unsigned char *pt_work = NULL;
+   symmetric_key *skey;
+   int            err;
+   unsigned long  len, L, x, y, z, CTRlen;
+
+   if (uskey == NULL) {
+      LTC_ARGCHK(key    != NULL);
+   }
+   LTC_ARGCHK(nonce  != NULL);
+   if (headerlen > 0) {
+      LTC_ARGCHK(header != NULL);
+   }
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+   pt_real = pt;
+
+#ifdef LTC_FAST
+   if (16 % sizeof(LTC_FAST_TYPE)) {
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+
+   /* check cipher input */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   if (cipher_descriptor[cipher].block_length != 16) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* make sure the taglen is valid */
+   if (*taglen < 4 || *taglen > 16 || (*taglen % 2) == 1 || headerlen > 0x7fffffffu) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* is there an accelerator? */
+   if (cipher_descriptor[cipher].accel_ccm_memory != NULL) {
+       return cipher_descriptor[cipher].accel_ccm_memory(
+           key,    keylen,
+           uskey,
+           nonce,  noncelen,
+           header, headerlen,
+           pt,     ptlen,
+           ct,
+           tag,    taglen,
+           direction);
+   }
+
+   /* let's get the L value */
+   len = ptlen;
+   L   = 0;
+   while (len) {
+      ++L;
+      len >>= 8;
+   }
+   if (L <= 1) {
+      L = 2;
+   }
+
+   /* increase L to match the nonce len */
+   noncelen = (noncelen > 13) ? 13 : noncelen;
+   if ((15 - noncelen) > L) {
+      L = 15 - noncelen;
+   }
+   if (L > 8) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* allocate mem for the symmetric key */
+   if (uskey == NULL) {
+      skey = XMALLOC(sizeof(*skey));
+      if (skey == NULL) {
+         return CRYPT_MEM;
+      }
+
+      /* initialize the cipher */
+      if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) {
+         XFREE(skey);
+         return err;
+      }
+   } else {
+      skey = uskey;
+   }
+
+   /* initialize buffer for pt */
+   if (direction == CCM_DECRYPT && ptlen > 0) {
+      pt_work = XMALLOC(ptlen);
+      if (pt_work == NULL) {
+         goto error;
+      }
+      pt = pt_work;
+   }
+
+   /* form B_0 == flags | Nonce N | l(m) */
+   x = 0;
+   PAD[x++] = (unsigned char)(((headerlen > 0) ? (1<<6) : 0) |
+            (((*taglen - 2)>>1)<<3)        |
+            (L-1));
+
+   /* nonce */
+   for (y = 0; y < 15 - L; y++) {
+       PAD[x++] = nonce[y];
+   }
+
+   /* store len */
+   len = ptlen;
+
+   /* shift len so the upper bytes of len are the contents of the length */
+   for (y = L; y < 4; y++) {
+       len <<= 8;
+   }
+
+   /* store l(m) (only store 32-bits) */
+   for (y = 0; L > 4 && (L-y)>4; y++) {
+       PAD[x++] = 0;
+   }
+   for (; y < L; y++) {
+       PAD[x++] = (unsigned char)((len >> 24) & 255);
+       len <<= 8;
+   }
+
+   /* encrypt PAD */
+   if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+       goto error;
+   }
+
+   /* handle header */
+   if (headerlen > 0) {
+      x = 0;
+
+      /* store length */
+      if (headerlen < ((1UL<<16) - (1UL<<8))) {
+         PAD[x++] ^= (headerlen>>8) & 255;
+         PAD[x++] ^= headerlen & 255;
+      } else {
+         PAD[x++] ^= 0xFF;
+         PAD[x++] ^= 0xFE;
+         PAD[x++] ^= (headerlen>>24) & 255;
+         PAD[x++] ^= (headerlen>>16) & 255;
+         PAD[x++] ^= (headerlen>>8) & 255;
+         PAD[x++] ^= headerlen & 255;
+      }
+
+      /* now add the data */
+      for (y = 0; y < headerlen; y++) {
+          if (x == 16) {
+             /* full block so let's encrypt it */
+             if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+                goto error;
+             }
+             x = 0;
+          }
+          PAD[x++] ^= header[y];
+      }
+
+      /* remainder */
+      if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+         goto error;
+      }
+   }
+
+   /* setup the ctr counter */
+   x = 0;
+
+   /* flags */
+   ctr[x++] = (unsigned char)L-1;
+
+   /* nonce */
+   for (y = 0; y < (16 - (L+1)); ++y) {
+      ctr[x++] = nonce[y];
+   }
+   /* offset */
+   while (x < 16) {
+      ctr[x++] = 0;
+   }
+
+   x      = 0;
+   CTRlen = 16;
+
+   /* now handle the PT */
+   if (ptlen > 0) {
+      y = 0;
+#ifdef LTC_FAST
+      if (ptlen & ~15)  {
+          if (direction == CCM_ENCRYPT) {
+             for (; y < (ptlen & ~15); y += 16) {
+                /* increment the ctr? */
+                for (z = 15; z > 15-L; z--) {
+                    ctr[z] = (ctr[z] + 1) & 255;
+                    if (ctr[z]) break;
+                }
+                if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
+                   goto error;
+                }
+
+                /* xor the PT against the pad first */
+                for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
+                    *(LTC_FAST_TYPE_PTR_CAST(&PAD[z]))  ^= *(LTC_FAST_TYPE_PTR_CAST(&pt[y+z]));
+                    *(LTC_FAST_TYPE_PTR_CAST(&ct[y+z])) = *(LTC_FAST_TYPE_PTR_CAST(&pt[y+z])) ^ *(LTC_FAST_TYPE_PTR_CAST(&CTRPAD[z]));
+                }
+                if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+                   goto error;
+                }
+             }
+          } else { /* direction == CCM_DECRYPT */
+             for (; y < (ptlen & ~15); y += 16) {
+                /* increment the ctr? */
+                for (z = 15; z > 15-L; z--) {
+                    ctr[z] = (ctr[z] + 1) & 255;
+                    if (ctr[z]) break;
+                }
+                if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
+                   goto error;
+                }
+
+                /* xor the PT against the pad last */
+                for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
+                    *(LTC_FAST_TYPE_PTR_CAST(&pt[y+z])) = *(LTC_FAST_TYPE_PTR_CAST(&ct[y+z])) ^ *(LTC_FAST_TYPE_PTR_CAST(&CTRPAD[z]));
+                    *(LTC_FAST_TYPE_PTR_CAST(&PAD[z]))  ^= *(LTC_FAST_TYPE_PTR_CAST(&pt[y+z]));
+                }
+                if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+                   goto error;
+                }
+             }
+          }
+      }
+#endif
+
+      for (; y < ptlen; y++) {
+          /* increment the ctr? */
+          if (CTRlen == 16) {
+             for (z = 15; z > 15-L; z--) {
+                 ctr[z] = (ctr[z] + 1) & 255;
+                 if (ctr[z]) break;
+             }
+             if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
+                goto error;
+             }
+             CTRlen = 0;
+          }
+
+          /* if we encrypt we add the bytes to the MAC first */
+          if (direction == CCM_ENCRYPT) {
+             b     = pt[y];
+             ct[y] = b ^ CTRPAD[CTRlen++];
+          } else {
+             b     = ct[y] ^ CTRPAD[CTRlen++];
+             pt[y] = b;
+          }
+
+          if (x == 16) {
+             if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+                goto error;
+             }
+             x = 0;
+          }
+          PAD[x++] ^= b;
+      }
+
+      if (x != 0) {
+         if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
+            goto error;
+         }
+      }
+   }
+
+   /* setup CTR for the TAG (zero the count) */
+   for (y = 15; y > 15 - L; y--) {
+      ctr[y] = 0x00;
+   }
+   if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
+      goto error;
+   }
+
+   if (skey != uskey) {
+      cipher_descriptor[cipher].done(skey);
+#ifdef LTC_CLEAN_STACK
+      zeromem(skey,   sizeof(*skey));
+#endif
+   }
+
+   if (direction == CCM_ENCRYPT) {
+      /* store the TAG */
+      for (x = 0; x < 16 && x < *taglen; x++) {
+          tag[x] = PAD[x] ^ CTRPAD[x];
+      }
+      *taglen = x;
+   } else { /* direction == CCM_DECRYPT */
+      /* decrypt the tag */
+      for (x = 0; x < 16 && x < *taglen; x++) {
+         ptTag[x] = tag[x] ^ CTRPAD[x];
+      }
+      *taglen = x;
+
+      /* check validity of the decrypted tag against the computed PAD (in constant time) */
+      /* HACK: the boolean value of XMEM_NEQ becomes either 0 (CRYPT_OK) or 1 (CRYPT_ERR).
+       *       there should be a better way of setting the correct error code in constant
+       *       time.
+       */
+      err = XMEM_NEQ(ptTag, PAD, *taglen);
+
+      /* Zero the plaintext if the tag was invalid (in constant time) */
+      if (ptlen > 0) {
+         copy_or_zeromem(pt, pt_real, ptlen, err);
+      }
+   }
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(PAD,    sizeof(PAD));
+   zeromem(CTRPAD, sizeof(CTRPAD));
+   if (pt_work != NULL) {
+     zeromem(pt_work, ptlen);
+   }
+#endif
+error:
+   if (pt_work) {
+      XFREE(pt_work);
+   }
+   if (skey != uskey) {
+      XFREE(skey);
+   }
+
+   return err;
+}
+
+#endif

Some files were not shown because too many files changed in this diff