Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
openssl
提交
20da8b8f
O
openssl
项目概览
btwise
/
openssl
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
20da8b8f
编写于
12月 02, 2006
作者:
A
Andy Polyakov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Camellia portability fixes.
Submitted by: Masashi Fujita, NTT
上级
ae93dc13
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
128 addition
and
147 deletion
+128
-147
crypto/camellia/camellia.c
crypto/camellia/camellia.c
+33
-97
crypto/camellia/cmll_cbc.c
crypto/camellia/cmll_cbc.c
+61
-12
crypto/camellia/cmll_locl.h
crypto/camellia/cmll_locl.h
+26
-36
crypto/camellia/cmll_misc.c
crypto/camellia/cmll_misc.c
+8
-2
未找到文件。
crypto/camellia/camellia.c
浏览文件 @
20da8b8f
...
...
@@ -76,12 +76,7 @@
#include "camellia.h"
#include "cmll_locl.h"
/*
* must be defined uint32_t
*/
/* key constants */
#define CAMELLIA_SIGMA1L (0xA09E667FL)
#define CAMELLIA_SIGMA1R (0x3BCC908BL)
#define CAMELLIA_SIGMA2L (0xB67AE858L)
...
...
@@ -100,18 +95,9 @@
*/
/* e is pointer of subkey */
#ifdef L_ENDIAN
#define CamelliaSubkeyL(INDEX) (subkey[(INDEX)*2 + 1])
#define CamelliaSubkeyR(INDEX) (subkey[(INDEX)*2])
#else
/* big endian */
#define CamelliaSubkeyL(INDEX) (subkey[(INDEX)*2])
#define CamelliaSubkeyR(INDEX) (subkey[(INDEX)*2 + 1])
#endif
/* IS_LITTLE_ENDIAN */
/* rotation right shift 1byte */
#define CAMELLIA_RR8(x) (((x) >> 8) + ((x) << 24))
/* rotation left shift 1bit */
...
...
@@ -170,44 +156,6 @@ do \
* for speed up
*
*/
#if !defined(_MSC_VER)
#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
do \
{ \
t0 = kll; \
t2 = krr; \
t0 &= ll; \
t2 |= rr; \
rl ^= t2; \
lr ^= CAMELLIA_RL1(t0); \
t3 = krl; \
t1 = klr; \
t3 &= rl; \
t1 |= lr; \
ll ^= t1; \
rr ^= CAMELLIA_RL1(t3); \
} while(0)
#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) \
do \
{ \
ir = CAMELLIA_SP1110(xr & 0xff); \
il = CAMELLIA_SP1110((xl>>24) & 0xff); \
ir ^= CAMELLIA_SP0222((xr>>24) & 0xff); \
il ^= CAMELLIA_SP0222((xl>>16) & 0xff); \
ir ^= CAMELLIA_SP3033((xr>>16) & 0xff); \
il ^= CAMELLIA_SP3033((xl>>8) & 0xff); \
ir ^= CAMELLIA_SP4404((xr>>8) & 0xff); \
il ^= CAMELLIA_SP4404(xl & 0xff); \
il ^= kl; \
ir ^= il ^ kr; \
yl ^= ir; \
yr ^= CAMELLIA_RR8(il) ^ ir; \
} while(0)
#else
/* for MS-VC */
#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
do \
{ \
...
...
@@ -249,9 +197,8 @@ do \
yl ^= ir; \
yr ^= il; \
} while(0)
#endif
static
const
u
int32_t
camellia_sp1110
[
256
]
=
static
const
u
32
camellia_sp1110
[
256
]
=
{
0x70707000
,
0x82828200
,
0x2c2c2c00
,
0xececec00
,
0xb3b3b300
,
0x27272700
,
0xc0c0c000
,
0xe5e5e500
,
...
...
@@ -319,7 +266,7 @@ static const uint32_t camellia_sp1110[256] =
0x77777700
,
0xc7c7c700
,
0x80808000
,
0x9e9e9e00
,
};
static
const
u
int32_t
camellia_sp0222
[
256
]
=
static
const
u
32
camellia_sp0222
[
256
]
=
{
0x00e0e0e0
,
0x00050505
,
0x00585858
,
0x00d9d9d9
,
0x00676767
,
0x004e4e4e
,
0x00818181
,
0x00cbcbcb
,
...
...
@@ -387,7 +334,7 @@ static const uint32_t camellia_sp0222[256] =
0x00eeeeee
,
0x008f8f8f
,
0x00010101
,
0x003d3d3d
,
};
static
const
u
int32_t
camellia_sp3033
[
256
]
=
static
const
u
32
camellia_sp3033
[
256
]
=
{
0x38003838
,
0x41004141
,
0x16001616
,
0x76007676
,
0xd900d9d9
,
0x93009393
,
0x60006060
,
0xf200f2f2
,
...
...
@@ -455,7 +402,7 @@ static const uint32_t camellia_sp3033[256] =
0xbb00bbbb
,
0xe300e3e3
,
0x40004040
,
0x4f004f4f
,
};
static
const
u
int32_t
camellia_sp4404
[
256
]
=
static
const
u
32
camellia_sp4404
[
256
]
=
{
0x70700070
,
0x2c2c002c
,
0xb3b300b3
,
0xc0c000c0
,
0xe4e400e4
,
0x57570057
,
0xeaea00ea
,
0xaeae00ae
,
...
...
@@ -523,20 +470,19 @@ static const uint32_t camellia_sp4404[256] =
0xe3e300e3
,
0xf4f400f4
,
0xc7c700c7
,
0x9e9e009e
,
};
/**
* Stuff related to the Camellia key schedule
*/
#define subl(x) subL[(x)]
#define subr(x) subR[(x)]
void
camellia_setup128
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
)
void
camellia_setup128
(
const
u
8
*
key
,
u32
*
subkey
)
{
u
int32_t
kll
,
klr
,
krl
,
krr
;
u
int32_t
il
,
ir
,
t0
,
t1
,
w0
,
w1
;
u
int32_t
kw4l
,
kw4r
,
dw
,
tl
,
tr
;
u
int32_t
subL
[
26
];
u
int32_t
subR
[
26
];
u
32
kll
,
klr
,
krl
,
krr
;
u
32
il
,
ir
,
t0
,
t1
,
w0
,
w1
;
u
32
kw4l
,
kw4r
,
dw
,
tl
,
tr
;
u
32
subL
[
26
];
u
32
subR
[
26
];
/**
* k == kll || klr || krl || krr (|| is concatination)
...
...
@@ -833,14 +779,14 @@ void camellia_setup128(const unsigned char *key, uint32_t *subkey)
return
;
}
void
camellia_setup256
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
)
void
camellia_setup256
(
const
u
8
*
key
,
u32
*
subkey
)
{
u
int32_t
kll
,
klr
,
krl
,
krr
;
/* left half of key */
u
int32_t
krll
,
krlr
,
krrl
,
krrr
;
/* right half of key */
u
int32_t
il
,
ir
,
t0
,
t1
,
w0
,
w1
;
/* temporary variables */
u
int32_t
kw4l
,
kw4r
,
dw
,
tl
,
tr
;
u
int32_t
subL
[
34
];
u
int32_t
subR
[
34
];
u
32
kll
,
klr
,
krl
,
krr
;
/* left half of key */
u
32
krll
,
krlr
,
krrl
,
krrr
;
/* right half of key */
u
32
il
,
ir
,
t0
,
t1
,
w0
,
w1
;
/* temporary variables */
u
32
kw4l
,
kw4r
,
dw
,
tl
,
tr
;
u
32
subL
[
34
];
u
32
subR
[
34
];
/**
* key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
...
...
@@ -1245,18 +1191,18 @@ void camellia_setup256(const unsigned char *key, uint32_t *subkey)
return
;
}
void
camellia_setup192
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
)
void
camellia_setup192
(
const
u
8
*
key
,
u32
*
subkey
)
{
u
nsigned
char
kk
[
32
];
u
int32_t
krll
,
krlr
,
krrl
,
krrr
;
u
8
kk
[
32
];
u
32
krll
,
krlr
,
krrl
,
krrr
;
memcpy
(
kk
,
key
,
24
);
memcpy
((
u
nsigned
char
*
)
&
krll
,
key
+
16
,
4
);
memcpy
((
u
nsigned
char
*
)
&
krlr
,
key
+
20
,
4
);
memcpy
((
u
8
*
)
&
krll
,
key
+
16
,
4
);
memcpy
((
u
8
*
)
&
krlr
,
key
+
20
,
4
);
krrl
=
~
krll
;
krrr
=
~
krlr
;
memcpy
(
kk
+
24
,
(
u
nsigned
char
*
)
&
krrl
,
4
);
memcpy
(
kk
+
28
,
(
u
nsigned
char
*
)
&
krrr
,
4
);
memcpy
(
kk
+
24
,
(
u
8
*
)
&
krrl
,
4
);
memcpy
(
kk
+
28
,
(
u
8
*
)
&
krrr
,
4
);
camellia_setup256
(
kk
,
subkey
);
return
;
}
...
...
@@ -1265,11 +1211,10 @@ void camellia_setup192(const unsigned char *key, uint32_t *subkey)
/**
* Stuff related to camellia encryption/decryption
*/
void
camellia_encrypt128
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
)
void
camellia_encrypt128
(
const
u
32
*
subkey
,
u32
*
io
)
{
u
int32_t
il
,
ir
,
t0
,
t1
;
u
32
il
,
ir
,
t0
,
t1
;
SWAP4WORD
(
io
);
/* pre whitening but absorb kw2*/
io
[
0
]
^=
CamelliaSubkeyL
(
0
);
io
[
1
]
^=
CamelliaSubkeyR
(
0
);
...
...
@@ -1352,16 +1297,13 @@ void camellia_encrypt128(const uint32_t *subkey, uint32_t *io)
io
[
1
]
=
io
[
3
];
io
[
2
]
=
t0
;
io
[
3
]
=
t1
;
SWAP4WORD
(
io
);
return
;
}
void
camellia_decrypt128
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
)
void
camellia_decrypt128
(
const
u
32
*
subkey
,
u32
*
io
)
{
uint32_t
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
SWAP4WORD
(
io
);
u32
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
/* pre whitening but absorb kw2*/
io
[
0
]
^=
CamelliaSubkeyL
(
24
);
...
...
@@ -1445,7 +1387,6 @@ void camellia_decrypt128(const uint32_t *subkey, uint32_t *io)
io
[
1
]
=
io
[
3
];
io
[
2
]
=
t0
;
io
[
3
]
=
t1
;
SWAP4WORD
(
io
);
return
;
}
...
...
@@ -1453,11 +1394,9 @@ void camellia_decrypt128(const uint32_t *subkey, uint32_t *io)
/**
* stuff for 192 and 256bit encryption/decryption
*/
void
camellia_encrypt256
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
)
void
camellia_encrypt256
(
const
u
32
*
subkey
,
u32
*
io
)
{
uint32_t
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
SWAP4WORD
(
io
);
u32
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
/* pre whitening but absorb kw2*/
io
[
0
]
^=
CamelliaSubkeyL
(
0
);
...
...
@@ -1565,16 +1504,14 @@ void camellia_encrypt256(const uint32_t *subkey, uint32_t *io)
io
[
1
]
=
io
[
3
];
io
[
2
]
=
t0
;
io
[
3
]
=
t1
;
SWAP4WORD
(
io
);
return
;
}
void
camellia_decrypt256
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
)
void
camellia_decrypt256
(
const
u
32
*
subkey
,
u32
*
io
)
{
u
int32_t
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
u
32
il
,
ir
,
t0
,
t1
;
/* temporary valiables */
SWAP4WORD
(
io
);
/* pre whitening but absorb kw2*/
io
[
0
]
^=
CamelliaSubkeyL
(
32
);
io
[
1
]
^=
CamelliaSubkeyR
(
32
);
...
...
@@ -1681,7 +1618,6 @@ void camellia_decrypt256(const uint32_t *subkey, uint32_t *io)
io
[
1
]
=
io
[
3
];
io
[
2
]
=
t0
;
io
[
3
]
=
t1
;
SWAP4WORD
(
io
);
return
;
}
...
...
crypto/camellia/cmll_cbc.c
浏览文件 @
20da8b8f
...
...
@@ -69,7 +69,8 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
unsigned
long
len
=
length
;
unsigned
char
tmp
[
CAMELLIA_BLOCK_SIZE
];
const
unsigned
char
*
iv
=
ivec
;
uint32_t
t32
[
UNITSIZE
];
u32
t32
[
UNITSIZE
];
const
union
{
long
one
;
char
little
;
}
camellia_endian
=
{
1
};
assert
(
in
&&
out
&&
key
&&
ivec
);
...
...
@@ -83,9 +84,13 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
{
while
(
len
>=
CAMELLIA_BLOCK_SIZE
)
{
XOR4WORD2
((
uint32_t
*
)
out
,
(
uint32_t
*
)
in
,
(
uint32_t
*
)
iv
);
key
->
enc
(
key
->
rd_key
,
(
uint32_t
*
)
out
);
XOR4WORD2
((
u32
*
)
out
,
(
u32
*
)
in
,
(
u32
*
)
iv
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
enc
(
key
->
rd_key
,
(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
iv
=
out
;
len
-=
CAMELLIA_BLOCK_SIZE
;
in
+=
CAMELLIA_BLOCK_SIZE
;
...
...
@@ -97,7 +102,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
out
[
n
]
=
in
[
n
]
^
iv
[
n
];
for
(
n
=
len
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
out
[
n
]
=
iv
[
n
];
key
->
enc
(
key
->
rd_key
,
(
uint32_t
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
enc
(
key
->
rd_key
,
(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
iv
=
out
;
}
memcpy
(
ivec
,
iv
,
CAMELLIA_BLOCK_SIZE
);
...
...
@@ -107,8 +116,12 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
while
(
len
>=
CAMELLIA_BLOCK_SIZE
)
{
memcpy
(
out
,
in
,
CAMELLIA_BLOCK_SIZE
);
key
->
dec
(
key
->
rd_key
,(
uint32_t
*
)
out
);
XOR4WORD
((
uint32_t
*
)
out
,
(
uint32_t
*
)
iv
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
dec
(
key
->
rd_key
,(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
XOR4WORD
((
u32
*
)
out
,
(
u32
*
)
iv
);
iv
=
in
;
len
-=
CAMELLIA_BLOCK_SIZE
;
in
+=
CAMELLIA_BLOCK_SIZE
;
...
...
@@ -117,7 +130,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
if
(
len
)
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
key
->
dec
(
key
->
rd_key
,
(
uint32_t
*
)
tmp
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
tmp
);
key
->
dec
(
key
->
rd_key
,
(
u32
*
)
tmp
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
tmp
);
for
(
n
=
0
;
n
<
len
;
++
n
)
out
[
n
]
=
tmp
[
n
]
^
iv
[
n
];
iv
=
in
;
...
...
@@ -129,8 +146,12 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
while
(
len
>=
CAMELLIA_BLOCK_SIZE
)
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
key
->
dec
(
key
->
rd_key
,
(
uint32_t
*
)
out
);
XOR4WORD
((
uint32_t
*
)
out
,
(
uint32_t
*
)
ivec
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
dec
(
key
->
rd_key
,
(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
XOR4WORD
((
u32
*
)
out
,
(
u32
*
)
ivec
);
memcpy
(
ivec
,
tmp
,
CAMELLIA_BLOCK_SIZE
);
len
-=
CAMELLIA_BLOCK_SIZE
;
in
+=
CAMELLIA_BLOCK_SIZE
;
...
...
@@ -139,7 +160,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
if
(
len
)
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
key
->
dec
(
key
->
rd_key
,(
uint32_t
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
dec
(
key
->
rd_key
,(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
for
(
n
=
0
;
n
<
len
;
++
n
)
out
[
n
]
^=
ivec
[
n
];
for
(
n
=
len
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
...
...
@@ -157,7 +182,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
for
(
n
=
0
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
out
[
n
]
=
in
[
n
]
^
iv
[
n
];
memcpy
(
t32
,
out
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
key
->
enc
(
key
->
rd_key
,
t32
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
memcpy
(
out
,
t32
,
CAMELLIA_BLOCK_SIZE
);
iv
=
out
;
len
-=
CAMELLIA_BLOCK_SIZE
;
...
...
@@ -170,7 +199,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
out
[
n
]
=
in
[
n
]
^
iv
[
n
];
for
(
n
=
len
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
out
[
n
]
=
iv
[
n
];
key
->
enc
(
key
->
rd_key
,
(
uint32_t
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
key
->
enc
(
key
->
rd_key
,
(
u32
*
)
out
);
if
(
camellia_endian
.
little
)
SWAP4WORD
((
u32
*
)
out
);
iv
=
out
;
}
memcpy
(
ivec
,
iv
,
CAMELLIA_BLOCK_SIZE
);
...
...
@@ -180,7 +213,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
while
(
len
>=
CAMELLIA_BLOCK_SIZE
)
{
memcpy
(
t32
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
key
->
dec
(
key
->
rd_key
,
t32
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
memcpy
(
out
,
t32
,
CAMELLIA_BLOCK_SIZE
);
for
(
n
=
0
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
out
[
n
]
^=
iv
[
n
];
...
...
@@ -193,7 +230,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
memcpy
(
t32
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
key
->
dec
(
key
->
rd_key
,
t32
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
memcpy
(
out
,
t32
,
CAMELLIA_BLOCK_SIZE
);
for
(
n
=
0
;
n
<
len
;
++
n
)
out
[
n
]
=
tmp
[
n
]
^
iv
[
n
];
...
...
@@ -207,7 +248,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
memcpy
(
t32
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
key
->
dec
(
key
->
rd_key
,
t32
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
memcpy
(
out
,
t32
,
CAMELLIA_BLOCK_SIZE
);
for
(
n
=
0
;
n
<
CAMELLIA_BLOCK_SIZE
;
++
n
)
out
[
n
]
^=
ivec
[
n
];
...
...
@@ -220,7 +265,11 @@ void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out,
{
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
memcpy
(
t32
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
key
->
dec
(
key
->
rd_key
,
t32
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
t32
);
memcpy
(
out
,
t32
,
CAMELLIA_BLOCK_SIZE
);
for
(
n
=
0
;
n
<
len
;
++
n
)
out
[
n
]
^=
ivec
[
n
];
...
...
crypto/camellia/cmll_locl.h
浏览文件 @
20da8b8f
...
...
@@ -73,13 +73,8 @@
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER)
typedef
unsigned
char
uint8_t
;
typedef
unsigned
int
uint32_t
;
typedef
unsigned
__int64
uint64_t
;
#else
#include <inttypes.h>
#endif
typedef
unsigned
char
u8
;
typedef
unsigned
int
u32
;
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -90,38 +85,33 @@ extern "C" {
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
# define SWAP(x) ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00 )
# define GETU32(p) SWAP(*((u
int32_t
*)(p)))
# define PUTU32(ct, st) { *((u
int32_t
*)(ct)) = SWAP((st)); }
# define GETU32(p) SWAP(*((u
32
*)(p)))
# define PUTU32(ct, st) { *((u
32
*)(ct)) = SWAP((st)); }
# define CAMELLIA_SWAP4(x) (x = ( _lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) )
#else
/* not windows */
# define GETU32(pt) (((uint32_t)(pt)[0] << 24) \
^ ((uint32_t)(pt)[1] << 16) \
^ ((uint32_t)(pt)[2] << 8) \
^ ((uint32_t)(pt)[3]))
# define PUTU32(ct, st) { (ct)[0] = (uint8_t)((st) >> 24); \
(ct)[1] = (uint8_t)((st) >> 16); \
(ct)[2] = (uint8_t)((st) >> 8); \
(ct)[3] = (uint8_t)(st); }
#ifdef L_ENDIAN
#if (defined (__GNUC__) && !defined(i386))
# define GETU32(pt) (((u32)(pt)[0] << 24) \
^ ((u32)(pt)[1] << 16) \
^ ((u32)(pt)[2] << 8) \
^ ((u32)(pt)[3]))
# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); \
(ct)[1] = (u8)((st) >> 16); \
(ct)[2] = (u8)((st) >> 8); \
(ct)[3] = (u8)(st); }
#if (defined (__GNUC__) && (defined(__x86_64__) || defined(__x86_64)))
#define CAMELLIA_SWAP4(x) \
do{\
asm("bswap %1" : "+r" (x));\
}while(0)
#else
/* not gcc */
#else
#define CAMELLIA_SWAP4(x) \
do{\
x = ((u
int32_t)x << 16) + ((uint32_t
)x >> 16);\
x = (((u
int32_t)x & 0xff00ff) << 8) + (((uint32_t
)x >> 8) & 0xff00ff);\
x = ((u
32)x << 16) + ((u32
)x >> 16);\
x = (((u
32)x & 0xff00ff) << 8) + (((u32
)x >> 8) & 0xff00ff);\
} while(0)
#endif
/* not gcc */
#else
/* big endian */
#define CAMELLIA_SWAP4(x)
#endif
/* L_ENDIAN */
#endif
#endif
#define COPY4WORD(dst, src) \
...
...
@@ -161,14 +151,14 @@ extern "C" {
}while(0)
void
camellia_setup128
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
);
void
camellia_setup192
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
);
void
camellia_setup256
(
const
u
nsigned
char
*
key
,
uint32_t
*
subkey
);
void
camellia_setup128
(
const
u
8
*
key
,
u32
*
subkey
);
void
camellia_setup192
(
const
u
8
*
key
,
u32
*
subkey
);
void
camellia_setup256
(
const
u
8
*
key
,
u32
*
subkey
);
void
camellia_encrypt128
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
);
void
camellia_decrypt128
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
);
void
camellia_encrypt256
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
);
void
camellia_decrypt256
(
const
u
int32_t
*
subkey
,
uint32_t
*
io
);
void
camellia_encrypt128
(
const
u
32
*
subkey
,
u32
*
io
);
void
camellia_decrypt128
(
const
u
32
*
subkey
,
u32
*
io
);
void
camellia_encrypt256
(
const
u
32
*
subkey
,
u32
*
io
);
void
camellia_decrypt256
(
const
u
32
*
subkey
,
u32
*
io
);
#ifdef __cplusplus
}
...
...
crypto/camellia/cmll_misc.c
浏览文件 @
20da8b8f
...
...
@@ -91,20 +91,26 @@ int Camellia_set_key(const unsigned char *userKey, const int bits,
void
Camellia_encrypt
(
const
unsigned
char
*
in
,
unsigned
char
*
out
,
const
CAMELLIA_KEY
*
key
)
{
uint32_t
tmp
[
UNITSIZE
];
u32
tmp
[
UNITSIZE
];
const
union
{
long
one
;
char
little
;
}
camellia_endian
=
{
1
};
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
tmp
);
key
->
enc
(
key
->
rd_key
,
tmp
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
tmp
);
memcpy
(
out
,
tmp
,
CAMELLIA_BLOCK_SIZE
);
}
void
Camellia_decrypt
(
const
unsigned
char
*
in
,
unsigned
char
*
out
,
const
CAMELLIA_KEY
*
key
)
{
uint32_t
tmp
[
UNITSIZE
];
u32
tmp
[
UNITSIZE
];
const
union
{
long
one
;
char
little
;
}
camellia_endian
=
{
1
};
memcpy
(
tmp
,
in
,
CAMELLIA_BLOCK_SIZE
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
tmp
);
key
->
dec
(
key
->
rd_key
,
tmp
);
if
(
camellia_endian
.
little
)
SWAP4WORD
(
tmp
);
memcpy
(
out
,
tmp
,
CAMELLIA_BLOCK_SIZE
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录