VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/Camellia.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/Camellia.c')
-rw-r--r--src/Crypto/Camellia.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Crypto/Camellia.c b/src/Crypto/Camellia.c
index f4fde8aa..675fc0bd 100644
--- a/src/Crypto/Camellia.c
+++ b/src/Crypto/Camellia.c
@@ -1,89 +1,89 @@
#include "Camellia.h"
#include "Common/Endian.h"
#include "Crypto/cpu.h"
#include "Crypto/misc.h"
#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM)
/* camellia.c ver 1.2.0-x86_64_asm1.1
*
* Copyright (c) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation) . All rights reserved.
*
* SuperCop integration:
- * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
+ * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
*
* VeraCrypt integration:
- * Copyright © 2017 Mounir IDRASSI <mounir.idrassi@idrix.fr>
+ * Copyright © 2017 Mounir IDRASSI <mounir.idrassi@idrix.fr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer as
* the first lines of this file unmodified.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY NTT ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL NTT BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Algorithm Specification
* http://info.isl.ntt.co.jp/crypt/eng/camellia/specifications.html
*/
/* Adapted for VeraCrypt */
#include "Common/Crypto.h"
#ifndef _WIN32
extern int IsAesHwCpuSupported ();
#endif
-void camellia_encrypt_asm(const byte *ctx, void *dst, const void *src);
-void camellia_decrypt_asm(const byte *ctx, void *dst, const void *src);
-void camellia_enc_blk2(const byte *ctx, byte *dst, const byte *src);
-void camellia_dec_blk2(const byte *ctx, byte *dst, const byte *src);
-void camellia_ecb_enc_16way(const byte *ctx, byte *dst, const byte *src);
-void camellia_ecb_dec_16way(const byte *ctx, byte *dst, const byte *src);
+void camellia_encrypt_asm(const uint8 *ctx, void *dst, const void *src);
+void camellia_decrypt_asm(const uint8 *ctx, void *dst, const void *src);
+void camellia_enc_blk2(const uint8 *ctx, uint8 *dst, const uint8 *src);
+void camellia_dec_blk2(const uint8 *ctx, uint8 *dst, const uint8 *src);
+void camellia_ecb_enc_16way(const uint8 *ctx, uint8 *dst, const uint8 *src);
+void camellia_ecb_dec_16way(const uint8 *ctx, uint8 *dst, const uint8 *src);
/* key constants */
#define CAMELLIA_SIGMA1L (0xA09E667FL)
#define CAMELLIA_SIGMA1R (0x3BCC908BL)
#define CAMELLIA_SIGMA2L (0xB67AE858L)
#define CAMELLIA_SIGMA2R (0x4CAA73B2L)
#define CAMELLIA_SIGMA3L (0xC6EF372FL)
#define CAMELLIA_SIGMA3R (0xE94F82BEL)
#define CAMELLIA_SIGMA4L (0x54FF53A5L)
#define CAMELLIA_SIGMA4R (0xF1D36F1CL)
#define CAMELLIA_SIGMA5L (0x10E527FAL)
#define CAMELLIA_SIGMA5R (0xDE682D1DL)
#define CAMELLIA_SIGMA6L (0xB05688C2L)
#define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
/*
* macros
*/
# define GETU32(p) bswap_32(*((uint32 *)(p)))
# define PUTU32(ct, st) {*((uint32 *)(ct)) = bswap_32((st));}
#define CamelliaSubkeyL(INDEX) (subkey[(INDEX)*2])
#define CamelliaSubkeyR(INDEX) (subkey[(INDEX)*2 + 1])
/* rotation right shift 1byte */
#define CAMELLIA_RR8(x) (((x) >> 8) + ((x) << 24))
/* rotation left shift 1bit */
@@ -1066,97 +1066,97 @@ void camellia_set_key(const unsigned __int8 key[], unsigned __int8 *ks)
CamelliaSubkeyR(25) = subr(25);
tl = subl(23) ^ (subr(23) & ~subr(25));
dw = tl & subl(25), tr = subr(23) ^ CAMELLIA_RL1(dw);
CamelliaSubkeyL(26) = tl ^ subl(27);
CamelliaSubkeyR(26) = tr ^ subr(27);
CamelliaSubkeyL(27) = subl(26) ^ subl(28);
CamelliaSubkeyR(27) = subr(26) ^ subr(28);
CamelliaSubkeyL(28) = subl(27) ^ subl(29);
CamelliaSubkeyR(28) = subr(27) ^ subr(29);
CamelliaSubkeyL(29) = subl(28) ^ subl(30);
CamelliaSubkeyR(29) = subr(28) ^ subr(30);
CamelliaSubkeyL(30) = subl(29) ^ subl(31);
CamelliaSubkeyR(30) = subr(29) ^ subr(31);
CamelliaSubkeyL(31) = subl(30);
CamelliaSubkeyR(31) = subr(30);
CamelliaSubkeyL(32) = subl(32) ^ subl(31);
CamelliaSubkeyR(32) = subr(32) ^ subr(31);
return;
}
void camellia_encrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks)
{
camellia_encrypt_asm (ks, outBlock, inBlock);
}
void camellia_decrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks)
{
camellia_decrypt_asm (ks, outBlock, inBlock);
}
-void camellia_encrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte* out_blk, uint32 blockCount)
+void camellia_encrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uint8* out_blk, uint32 blockCount)
{
#if !defined (_UEFI)
if ((blockCount >= 16) && IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
{
#if defined (TC_WINDOWS_DRIVER)
XSTATE_SAVE SaveState;
if (NT_SUCCESS (KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState)))
{
#endif
while (blockCount >= 16)
{
camellia_ecb_enc_16way (instance, out_blk, in_blk);
out_blk += 16 * 16;
in_blk += 16 * 16;
blockCount -= 16;
}
#if defined (TC_WINDOWS_DRIVER)
KeRestoreExtendedProcessorStateVC(&SaveState);
}
#endif
}
#endif
while (blockCount >= 2)
{
camellia_enc_blk2 (instance, out_blk, in_blk);
out_blk += 2 * 16;
in_blk += 2 * 16;
blockCount -= 2;
}
if (blockCount)
camellia_encrypt (in_blk, out_blk, instance);
}
-void camellia_decrypt_blocks(unsigned __int8 *instance, const byte* in_blk, byte* out_blk, uint32 blockCount)
+void camellia_decrypt_blocks(unsigned __int8 *instance, const uint8* in_blk, uint8* out_blk, uint32 blockCount)
{
#if !defined (_UEFI)
if ((blockCount >= 16) && IsCpuIntel() && IsAesHwCpuSupported () && HasSAVX()) /* on AMD cpu, AVX is too slow */
{
#if defined (TC_WINDOWS_DRIVER)
XSTATE_SAVE SaveState;
if (NT_SUCCESS (KeSaveExtendedProcessorStateVC(XSTATE_MASK_GSSE, &SaveState)))
{
#endif
while (blockCount >= 16)
{
camellia_ecb_dec_16way (instance, out_blk, in_blk);
out_blk += 16 * 16;
in_blk += 16 * 16;
blockCount -= 16;
}
#if defined (TC_WINDOWS_DRIVER)
KeRestoreExtendedProcessorStateVC(&SaveState);
}
#endif
}
#endif
while (blockCount >= 2)
{
camellia_dec_blk2 (instance, out_blk, in_blk);
out_blk += 2 * 16;
in_blk += 2 * 16;
blockCount -= 2;
}