Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dmitry Baryshkov
nettle
Commits
a9b47a42
Commit
a9b47a42
authored
Mar 18, 2014
by
Niels Möller
Browse files
Define and use nettle_cipher_func, for block ciphers.
parent
6bd43205
Changes
28
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
a9b47a42
2014-03-18 Niels Möller <nisse@lysator.liu.se>
* nettle-types.h (nettle_cipher_func): New typedef, similar to
nettle_crypt_func, but with a const context, intended for block
ciphers.
* nettle-meta.h (struct nettle_cipher): Use the nettle_cipher_func
type.
* Many other files affected: aes*-meta.c, camellia*-meta.c,
cast128-meta.c, serpent-meta.c, twofish-meta.c, cbc.[ch],
ctr.[ch], ctr.[ch], des-compat.c, eax.[ch], gcm*.[ch],
nettle-internal.*, testsuite/aes-test.c,
examples/nettle-benchmark.c, examples/nettle-openssl.c.
2014-03-16 Niels Möller <nisse@lysator.liu.se>
* chacha-set-key.c: Include string.h.
...
...
aes128-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_aes128 =
AES_BLOCK_SIZE
,
AES128_KEY_SIZE
,
(
nettle_set_key_func
*
)
aes128_set_encrypt_key
,
(
nettle_set_key_func
*
)
aes128_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
aes128_encrypt
,
(
nettle_c
rypt
_func
*
)
aes128_decrypt
(
nettle_c
ipher
_func
*
)
aes128_encrypt
,
(
nettle_c
ipher
_func
*
)
aes128_decrypt
};
aes192-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_aes192 =
AES_BLOCK_SIZE
,
AES192_KEY_SIZE
,
(
nettle_set_key_func
*
)
aes192_set_encrypt_key
,
(
nettle_set_key_func
*
)
aes192_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
aes192_encrypt
,
(
nettle_c
rypt
_func
*
)
aes192_decrypt
(
nettle_c
ipher
_func
*
)
aes192_encrypt
,
(
nettle_c
ipher
_func
*
)
aes192_decrypt
};
aes256-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_aes256 =
AES_BLOCK_SIZE
,
AES256_KEY_SIZE
,
(
nettle_set_key_func
*
)
aes256_set_encrypt_key
,
(
nettle_set_key_func
*
)
aes256_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
aes256_encrypt
,
(
nettle_c
rypt
_func
*
)
aes256_decrypt
(
nettle_c
ipher
_func
*
)
aes256_encrypt
,
(
nettle_c
ipher
_func
*
)
aes256_decrypt
};
arctwo-meta.c
View file @
a9b47a42
...
...
@@ -34,8 +34,8 @@
ARCTWO_BLOCK_SIZE, bits/8, \
(nettle_set_key_func *) arctwo ## bits ## _set_key, \
(nettle_set_key_func *) arctwo ## bits ## _set_key, \
(nettle_c
rypt
_func *) arctwo_encrypt, \
(nettle_c
rypt
_func *) arctwo_decrypt, \
(nettle_c
ipher
_func *) arctwo_encrypt, \
(nettle_c
ipher
_func *) arctwo_decrypt, \
}
const
struct
nettle_cipher
nettle_arctwo40
=
ARCTWO
(
40
);
...
...
@@ -51,6 +51,6 @@ const struct nettle_cipher nettle_arctwo_gutmann128 =
ARCTWO_BLOCK_SIZE
,
16
,
(
nettle_set_key_func
*
)
arctwo128_set_key_gutmann
,
(
nettle_set_key_func
*
)
arctwo128_set_key_gutmann
,
(
nettle_c
rypt
_func
*
)
arctwo_encrypt
,
(
nettle_c
rypt
_func
*
)
arctwo_decrypt
,
(
nettle_c
ipher
_func
*
)
arctwo_encrypt
,
(
nettle_c
ipher
_func
*
)
arctwo_decrypt
,
};
camellia128-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_camellia128 =
CAMELLIA_BLOCK_SIZE
,
CAMELLIA128_KEY_SIZE
,
(
nettle_set_key_func
*
)
camellia128_set_encrypt_key
,
(
nettle_set_key_func
*
)
camellia128_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
camellia128_crypt
,
(
nettle_c
rypt
_func
*
)
camellia128_crypt
(
nettle_c
ipher
_func
*
)
camellia128_crypt
,
(
nettle_c
ipher
_func
*
)
camellia128_crypt
};
camellia192-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_camellia192 =
CAMELLIA_BLOCK_SIZE
,
CAMELLIA192_KEY_SIZE
,
(
nettle_set_key_func
*
)
camellia192_set_encrypt_key
,
(
nettle_set_key_func
*
)
camellia192_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
camellia256_crypt
,
(
nettle_c
rypt
_func
*
)
camellia256_crypt
(
nettle_c
ipher
_func
*
)
camellia256_crypt
,
(
nettle_c
ipher
_func
*
)
camellia256_crypt
};
camellia256-meta.c
View file @
a9b47a42
...
...
@@ -35,6 +35,6 @@ const struct nettle_cipher nettle_camellia256 =
CAMELLIA_BLOCK_SIZE
,
CAMELLIA256_KEY_SIZE
,
(
nettle_set_key_func
*
)
camellia256_set_encrypt_key
,
(
nettle_set_key_func
*
)
camellia256_set_decrypt_key
,
(
nettle_c
rypt
_func
*
)
camellia256_crypt
,
(
nettle_c
rypt
_func
*
)
camellia256_crypt
(
nettle_c
ipher
_func
*
)
camellia256_crypt
,
(
nettle_c
ipher
_func
*
)
camellia256_crypt
};
cast128-meta.c
View file @
a9b47a42
...
...
@@ -33,6 +33,6 @@ const struct nettle_cipher nettle_cast128 =
CAST128_BLOCK_SIZE
,
CAST128_KEY_SIZE
,
(
nettle_set_key_func
*
)
cast128_set_key
,
(
nettle_set_key_func
*
)
cast128_set_key
,
(
nettle_c
rypt
_func
*
)
cast128_encrypt
,
(
nettle_c
rypt
_func
*
)
cast128_decrypt
(
nettle_c
ipher
_func
*
)
cast128_encrypt
,
(
nettle_c
ipher
_func
*
)
cast128_decrypt
};
cbc.c
View file @
a9b47a42
...
...
@@ -37,7 +37,7 @@
#include "nettle-internal.h"
void
cbc_encrypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
cbc_encrypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
iv
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
...
...
@@ -56,7 +56,7 @@ cbc_encrypt(void *ctx, nettle_crypt_func *f,
#define CBC_BUFFER_LIMIT 512
void
cbc_decrypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
cbc_decrypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
iv
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
...
...
cbc.h
View file @
a9b47a42
...
...
@@ -37,13 +37,13 @@ extern "C" {
#define cbc_decrypt nettle_cbc_decrypt
void
cbc_encrypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
cbc_encrypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
iv
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
void
cbc_decrypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
cbc_decrypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
iv
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
...
...
@@ -58,16 +58,16 @@ memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_encrypt((void *) &(self)->ctx, \
(nettle_c
rypt
_func *) (f), \
(nettle_c
ipher
_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
(length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_decrypt((void *) &(self)->ctx, \
(nettle_c
rypt
_func *) (f), \
(nettle_c
ipher
_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
(length), (dst), (src)))
#ifdef __cplusplus
}
...
...
ctr.c
View file @
a9b47a42
...
...
@@ -40,7 +40,7 @@
#define NBLOCKS 4
void
ctr_crypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
ctr_crypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
ctr
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
...
...
ctr.h
View file @
a9b47a42
...
...
@@ -37,7 +37,7 @@ extern "C" {
#define ctr_crypt nettle_ctr_crypt
void
ctr_crypt
(
void
*
ctx
,
nettle_c
rypt
_func
*
f
,
ctr_crypt
(
const
void
*
ctx
,
nettle_c
ipher
_func
*
f
,
size_t
block_size
,
uint8_t
*
ctr
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
...
...
@@ -51,9 +51,9 @@ memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
#define CTR_CRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: ctr_crypt((void *) &(self)->ctx, \
(nettle_c
rypt
_func *) (f), \
(nettle_c
ipher
_func *) (f), \
sizeof((self)->ctr), (self)->ctr, \
(length), (dst), (src)))
(length), (dst), (src)))
#ifdef __cplusplus
}
...
...
des-compat.c
View file @
a9b47a42
...
...
@@ -113,13 +113,13 @@ des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
switch
(
enc
)
{
case
DES_ENCRYPT
:
nettle_cbc_encrypt
(
ctx
,
(
nettle_c
rypt
_func
*
)
des_encrypt
,
nettle_cbc_encrypt
(
ctx
,
(
nettle_c
ipher
_func
*
)
des_encrypt
,
DES_BLOCK_SIZE
,
*
iv
,
length
,
*
dst
,
*
src
);
break
;
case
DES_DECRYPT
:
nettle_cbc_decrypt
(
ctx
,
(
nettle_c
rypt
_func
*
)
des_decrypt
,
(
nettle_c
ipher
_func
*
)
des_decrypt
,
DES_BLOCK_SIZE
,
*
iv
,
length
,
*
dst
,
*
src
);
break
;
...
...
@@ -166,12 +166,12 @@ des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
switch
(
enc
)
{
case
DES_ENCRYPT
:
nettle_cbc_encrypt
(
&
keys
,
(
nettle_c
rypt
_func
*
)
des_compat_des3_encrypt
,
nettle_cbc_encrypt
(
&
keys
,
(
nettle_c
ipher
_func
*
)
des_compat_des3_encrypt
,
DES_BLOCK_SIZE
,
*
iv
,
length
,
*
dst
,
*
src
);
break
;
case
DES_DECRYPT
:
nettle_cbc_decrypt
(
&
keys
,
(
nettle_c
rypt
_func
*
)
des_compat_des3_decrypt
,
nettle_cbc_decrypt
(
&
keys
,
(
nettle_c
ipher
_func
*
)
des_compat_des3_decrypt
,
DES_BLOCK_SIZE
,
*
iv
,
length
,
*
dst
,
*
src
);
break
;
...
...
eax.c
View file @
a9b47a42
...
...
@@ -56,7 +56,7 @@ block16_xor (union nettle_block16 *dst, const union nettle_block16 *src)
static
void
omac_update
(
union
nettle_block16
*
state
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
const
uint8_t
*
data
)
{
for
(;
length
>=
EAX_BLOCK_SIZE
;
...
...
@@ -79,7 +79,7 @@ omac_update (union nettle_block16 *state, const struct eax_key *key,
static
void
omac_final
(
union
nettle_block16
*
state
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
)
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
)
{
block16_xor
(
state
,
&
key
->
pad_block
);
f
(
cipher
,
EAX_BLOCK_SIZE
,
state
->
b
,
state
->
b
);
...
...
@@ -100,7 +100,7 @@ gf2_double (uint8_t *r, const uint8_t *a)
}
void
eax_set_key
(
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
)
eax_set_key
(
struct
eax_key
*
key
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
)
{
static
const
union
nettle_block16
zero_block
;
f
(
cipher
,
EAX_BLOCK_SIZE
,
key
->
pad_block
.
b
,
zero_block
.
b
);
...
...
@@ -111,7 +111,7 @@ eax_set_key (struct eax_key *key, void *cipher, nettle_crypt_func *f)
void
eax_set_nonce
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
nonce_length
,
const
uint8_t
*
nonce
)
{
omac_init
(
&
eax
->
omac_nonce
,
0
);
...
...
@@ -125,7 +125,7 @@ eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
void
eax_update
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
data_length
,
const
uint8_t
*
data
)
{
omac_update
(
&
eax
->
omac_data
,
key
,
cipher
,
f
,
data_length
,
data
);
...
...
@@ -133,7 +133,7 @@ eax_update (struct eax_ctx *eax, const struct eax_key *key,
void
eax_encrypt
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
ctr_crypt
(
cipher
,
f
,
EAX_BLOCK_SIZE
,
eax
->
ctr
.
b
,
length
,
dst
,
src
);
...
...
@@ -142,7 +142,7 @@ eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
void
eax_decrypt
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
omac_update
(
&
eax
->
omac_message
,
key
,
cipher
,
f
,
length
,
src
);
...
...
@@ -151,7 +151,7 @@ eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
void
eax_digest
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
digest
)
{
assert
(
length
>
0
);
...
...
eax.h
View file @
a9b47a42
...
...
@@ -71,31 +71,31 @@ struct eax_ctx
};
void
eax_set_key
(
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
);
eax_set_key
(
struct
eax_key
*
key
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
);
void
eax_set_nonce
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
nonce_length
,
const
uint8_t
*
nonce
);
void
eax_update
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
data_length
,
const
uint8_t
*
data
);
void
eax_encrypt
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
void
eax_decrypt
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
void
eax_digest
(
struct
eax_ctx
*
eax
,
const
struct
eax_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
digest
);
/* Put the cipher last, to get cipher-independent offsets for the EAX
...
...
@@ -107,37 +107,37 @@ eax_digest (struct eax_ctx *eax, const struct eax_key *key,
do { \
(set_key)(&(ctx)->cipher, (data)); \
if (0) (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0); \
eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_c
rypt
_func *) encrypt); \
eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_c
ipher
_func *) encrypt); \
} while (0)
#define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_c
rypt
_func *) (encrypt), \
&(ctx)->cipher, (nettle_c
ipher
_func *) (encrypt), \
(length), (nonce)))
#define EAX_UPDATE(ctx, encrypt, length, data) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_update (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_c
rypt
_func *) (encrypt), \
&(ctx)->cipher, (nettle_c
ipher
_func *) (encrypt), \
(length), (data)))
#define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_encrypt (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_c
rypt
_func *) (encrypt), \
&(ctx)->cipher, (nettle_c
ipher
_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_decrypt (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_c
rypt
_func *) (encrypt), \
&(ctx)->cipher, (nettle_c
ipher
_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_digest (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_c
rypt
_func *) (encrypt), \
&(ctx)->cipher, (nettle_c
ipher
_func *) (encrypt), \
(length), (digest)))
struct
eax_aes128_ctx
EAX_CTX
(
struct
aes128_ctx
);
...
...
examples/nettle-benchmark.c
View file @
a9b47a42
...
...
@@ -186,7 +186,7 @@ bench_hash(void *arg)
struct
bench_cipher_info
{
void
*
ctx
;
nettle_c
rypt
_func
*
crypt
;
nettle_c
ipher
_func
*
crypt
;
uint8_t
*
data
;
};
...
...
@@ -200,7 +200,7 @@ bench_cipher(void *arg)
struct
bench_cbc_info
{
void
*
ctx
;
nettle_c
rypt
_func
*
crypt
;
nettle_c
ipher
_func
*
crypt
;
uint8_t
*
data
;
...
...
examples/nettle-openssl.c
View file @
a9b47a42
...
...
@@ -89,9 +89,9 @@ openssl_aes256_set_decrypt_key(void *ctx, const uint8_t *key)
AES_set_decrypt_key
(
key
,
256
,
ctx
);
}
static
nettle_c
rypt
_func
openssl_aes_encrypt
;
static
nettle_c
ipher
_func
openssl_aes_encrypt
;
static
void
openssl_aes_encrypt
(
void
*
ctx
,
size_t
length
,
openssl_aes_encrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
AES_BLOCK_SIZE
));
...
...
@@ -104,9 +104,9 @@ openssl_aes_encrypt(void *ctx, size_t length,
}
}
static
nettle_c
rypt
_func
openssl_aes_decrypt
;
static
nettle_c
ipher
_func
openssl_aes_decrypt
;
static
void
openssl_aes_decrypt
(
void
*
ctx
,
size_t
length
,
openssl_aes_decrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
AES_BLOCK_SIZE
));
...
...
@@ -157,9 +157,9 @@ openssl_bf128_set_key(void *ctx, const uint8_t *key)
BF_set_key
(
ctx
,
16
,
key
);
}
static
nettle_c
rypt
_func
openssl_bf_encrypt
;
static
nettle_c
ipher
_func
openssl_bf_encrypt
;
static
void
openssl_bf_encrypt
(
void
*
ctx
,
size_t
length
,
openssl_bf_encrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
BF_BLOCK
));
...
...
@@ -172,9 +172,9 @@ openssl_bf_encrypt(void *ctx, size_t length,
}
}
static
nettle_c
rypt
_func
openssl_bf_decrypt
;
static
nettle_c
ipher
_func
openssl_bf_decrypt
;
static
void
openssl_bf_decrypt
(
void
*
ctx
,
size_t
length
,
openssl_bf_decrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
BF_BLOCK
));
...
...
@@ -210,30 +210,32 @@ openssl_des_set_key(void *ctx, const uint8_t *key)
#define DES_BLOCK_SIZE 8
static
nettle_c
rypt
_func
openssl_des_encrypt
;
static
nettle_c
ipher
_func
openssl_des_encrypt
;
static
void
openssl_des_encrypt
(
void
*
ctx
,
size_t
length
,
openssl_des_encrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
DES_BLOCK_SIZE
));
while
(
length
)
{
DES_ecb_encrypt
((
void
*
)
src
,
(
void
*
)
dst
,
ctx
,
DES_ENCRYPT
);
DES_ecb_encrypt
((
void
*
)
src
,
(
void
*
)
dst
,
(
void
*
)
ctx
,
DES_ENCRYPT
);
length
-=
DES_BLOCK_SIZE
;
dst
+=
DES_BLOCK_SIZE
;
src
+=
DES_BLOCK_SIZE
;
}
}
static
nettle_c
rypt
_func
openssl_des_decrypt
;
static
nettle_c
ipher
_func
openssl_des_decrypt
;
static
void
openssl_des_decrypt
(
void
*
ctx
,
size_t
length
,
openssl_des_decrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
DES_BLOCK_SIZE
));
while
(
length
)
{
DES_ecb_encrypt
((
void
*
)
src
,
(
void
*
)
dst
,
ctx
,
DES_DECRYPT
);
DES_ecb_encrypt
((
void
*
)
src
,
(
void
*
)
dst
,
(
void
*
)
ctx
,
DES_DECRYPT
);
length
-=
DES_BLOCK_SIZE
;
dst
+=
DES_BLOCK_SIZE
;
src
+=
DES_BLOCK_SIZE
;
...
...
@@ -257,9 +259,9 @@ openssl_cast128_set_key(void *ctx, const uint8_t *key)
CAST_set_key
(
ctx
,
16
,
key
);
}
static
nettle_c
rypt
_func
openssl_cast_encrypt
;
static
nettle_c
ipher
_func
openssl_cast_encrypt
;
static
void
openssl_cast_encrypt
(
void
*
ctx
,
size_t
length
,
openssl_cast_encrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
CAST_BLOCK
));
...
...
@@ -272,9 +274,9 @@ openssl_cast_encrypt(void *ctx, size_t length,
}
}
static
nettle_c
rypt
_func
openssl_cast_decrypt
;
static
nettle_c
ipher
_func
openssl_cast_decrypt
;
static
void
openssl_cast_decrypt
(
void
*
ctx
,
size_t
length
,
openssl_cast_decrypt
(
const
void
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
CAST_BLOCK
));
...
...
gcm-aes.c
View file @
a9b47a42
...
...
@@ -34,7 +34,7 @@ gcm_aes_set_key(struct gcm_aes_ctx *ctx, size_t length, const uint8_t *key)
{
aes_set_encrypt_key
(
&
ctx
->
cipher
,
length
,
key
);
gcm_set_key
(
&
ctx
->
key
,
&
ctx
->
cipher
,
(
nettle_c
rypt
_func
*
)
aes_encrypt
);
(
nettle_c
ipher
_func
*
)
aes_encrypt
);
}
void
...
...
gcm.c
View file @
a9b47a42
...
...
@@ -328,7 +328,7 @@ gcm_gf_mul (union nettle_block16 *x, const union nettle_block16 *table)
*/
void
gcm_set_key
(
struct
gcm_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
)
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
)
{
/* Middle element if GCM_TABLE_BITS > 0, otherwise the first
element */
...
...
@@ -427,7 +427,7 @@ gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
}
static
void
gcm_crypt
(
struct
gcm_ctx
*
ctx
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
gcm_crypt
(
struct
gcm_ctx
*
ctx
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
uint8_t
buffer
[
GCM_BLOCK_SIZE
];
...
...
@@ -465,7 +465,7 @@ gcm_crypt(struct gcm_ctx *ctx, void *cipher, nettle_crypt_func *f,
void
gcm_encrypt
(
struct
gcm_ctx
*
ctx
,
const
struct
gcm_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
ctx
->
data_size
%
GCM_BLOCK_SIZE
==
0
);
...
...
@@ -478,7 +478,7 @@ gcm_encrypt (struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_decrypt
(
struct
gcm_ctx
*
ctx
,
const
struct
gcm_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
ctx
->
data_size
%
GCM_BLOCK_SIZE
==
0
);
...
...
@@ -491,7 +491,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_digest
(
struct
gcm_ctx
*
ctx
,
const
struct
gcm_key
*
key
,
void
*
cipher
,
nettle_c
rypt
_func
*
f
,
const
void
*
cipher
,
nettle_c
ipher
_func
*
f
,
size_t
length
,
uint8_t
*
digest
)
{
uint8_t
buffer
[
GCM_BLOCK_SIZE
];
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment