Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nettle
nettle
Commits
69208ec1
Commit
69208ec1
authored
Feb 19, 2018
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Mostly aesthetic changes to CMAC.
parent
0c4cccd0
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ChangeLog
+13
-1
13 additions, 1 deletion
ChangeLog
cmac.c
+8
-9
8 additions, 9 deletions
cmac.c
cmac.h
+18
-15
18 additions, 15 deletions
cmac.h
testsuite/cmac-test.c
+16
-15
16 additions, 15 deletions
testsuite/cmac-test.c
with
55 additions
and
40 deletions
ChangeLog
+
13
−
1
View file @
69208ec1
2018-02-19 Niels Möller <nisse@lysator.liu.se>
Mostly aesthetic changes. Besides indentation:
* cmac.h (struct cmac128): Rename, to cmac128_ctx.
(CMAC128_CTX): Rename first member from data to ctx.
* cmac.c: Use const void * as the type for cipher arguments.
(block_mulx): Un-inline.
(cmac128_set_key): Make a constant function local.
* testsuite/cmac-test.c: Delete local typedefs.
2018-02-19 Nikos Mavrogiannopoulos <nmav@redhat.com>
2018-02-19 Nikos Mavrogiannopoulos <nmav@redhat.com>
Add support for CMAC.
Add support for CMAC.
...
...
This diff is collapsed.
Click to expand it.
cmac.c
+
8
−
9
View file @
69208ec1
...
@@ -46,13 +46,8 @@
...
@@ -46,13 +46,8 @@
#include
"nettle-internal.h"
#include
"nettle-internal.h"
#include
"macros.h"
#include
"macros.h"
static
const
uint8_t
const_zero
[]
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
/* shift one and XOR with 0x87. */
/* shift one and XOR with 0x87. */
static
inline
void
static
void
block_mulx
(
union
nettle_block16
*
dst
,
block_mulx
(
union
nettle_block16
*
dst
,
const
union
nettle_block16
*
src
)
const
union
nettle_block16
*
src
)
{
{
...
@@ -70,9 +65,13 @@ block_mulx(union nettle_block16 *dst,
...
@@ -70,9 +65,13 @@ block_mulx(union nettle_block16 *dst,
}
}
void
void
cmac128_set_key
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_set_key
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
)
nettle_cipher_func
*
encrypt
)
{
{
static
const
uint8_t
const_zero
[]
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
union
nettle_block16
*
L
=
&
ctx
->
block
;
union
nettle_block16
*
L
=
&
ctx
->
block
;
memset
(
ctx
,
0
,
sizeof
(
*
ctx
));
memset
(
ctx
,
0
,
sizeof
(
*
ctx
));
...
@@ -86,7 +85,7 @@ cmac128_set_key(struct cmac128 *ctx, void *cipher,
...
@@ -86,7 +85,7 @@ cmac128_set_key(struct cmac128 *ctx, void *cipher,
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
void
void
cmac128_update
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_update
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
,
nettle_cipher_func
*
encrypt
,
size_t
msg_len
,
const
uint8_t
*
msg
)
size_t
msg_len
,
const
uint8_t
*
msg
)
{
{
...
@@ -131,7 +130,7 @@ cmac128_update(struct cmac128 *ctx, void *cipher,
...
@@ -131,7 +130,7 @@ cmac128_update(struct cmac128 *ctx, void *cipher,
}
}
void
void
cmac128_digest
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_digest
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
,
nettle_cipher_func
*
encrypt
,
unsigned
length
,
unsigned
length
,
uint8_t
*
dst
)
uint8_t
*
dst
)
...
...
This diff is collapsed.
Click to expand it.
cmac.h
+
18
−
15
View file @
69208ec1
...
@@ -55,52 +55,55 @@ extern "C" {
...
@@ -55,52 +55,55 @@ extern "C" {
#define cmac_aes256_update nettle_cmac_aes256_update
#define cmac_aes256_update nettle_cmac_aes256_update
#define cmac_aes256_digest nettle_cmac_aes256_digest
#define cmac_aes256_digest nettle_cmac_aes256_digest
struct
cmac128
struct
cmac128
_ctx
{
{
/* Key */
union
nettle_block16
K1
;
union
nettle_block16
K1
;
union
nettle_block16
K2
;
union
nettle_block16
K2
;
/* MAC state */
union
nettle_block16
X
;
union
nettle_block16
X
;
/* Block buffer */
union
nettle_block16
block
;
union
nettle_block16
block
;
size_t
index
;
size_t
index
;
};
};
void
void
cmac128_set_key
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_set_key
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
);
nettle_cipher_func
*
encrypt
);
void
void
cmac128_update
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_update
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
,
nettle_cipher_func
*
encrypt
,
size_t
msg_len
,
const
uint8_t
*
msg
);
size_t
msg_len
,
const
uint8_t
*
msg
);
void
void
cmac128_digest
(
struct
cmac128
*
ctx
,
void
*
cipher
,
cmac128_digest
(
struct
cmac128
_ctx
*
ctx
,
const
void
*
cipher
,
nettle_cipher_func
*
encrypt
,
nettle_cipher_func
*
encrypt
,
unsigned
length
,
unsigned
length
,
uint8_t
*
ou
t
);
uint8_t
*
diges
t
);
#define CMAC128_CTX(type) \
#define CMAC128_CTX(type) \
{ struct cmac128
data
; type cipher; }
{ struct cmac128
_ctx ctx
; type cipher; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CMAC128_SET_KEY(
ctx
, set_key, encrypt, cmac_key) \
#define CMAC128_SET_KEY(
self
, set_key, encrypt, cmac_key) \
do { \
do { \
(set_key)(&(
ctx
)->cipher, (cmac_key)); \
(set_key)(&(
self
)->cipher, (cmac_key)); \
if (0) (encrypt)(&(
ctx
)->cipher, ~(size_t) 0, \
if (0) (encrypt)(&(
self
)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0); \
(uint8_t *) 0, (const uint8_t *) 0); \
cmac128_set_key(&(
ctx)->data, &(ctx
)->cipher, \
cmac128_set_key(&(
self)->ctx, &(self
)->cipher, \
(nettle_cipher_func *) (encrypt)); \
(nettle_cipher_func *) (encrypt)); \
} while (0)
} while (0)
#define CMAC128_UPDATE(
ctx
, encrypt, length, src) \
#define CMAC128_UPDATE(
self
, encrypt, length, src) \
cmac128_update(&(
ctx)->data, &(ctx
)->cipher, \
cmac128_update(&(
self)->ctx, &(self
)->cipher, \
(nettle_cipher_func *)encrypt, (length), (src))
(nettle_cipher_func *)encrypt, (length), (src))
#define CMAC128_DIGEST(
ctx
, encrypt, length, digest) \
#define CMAC128_DIGEST(
self
, encrypt, length, digest) \
(0 ? (encrypt)(&(
ctx
)->cipher, ~(size_t) 0, \
(0 ? (encrypt)(&(
self
)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
(uint8_t *) 0, (const uint8_t *) 0) \
: cmac128_digest(&(
ctx)->data, &(ctx
)->cipher, \
: cmac128_digest(&(
self)->ctx, &(self
)->cipher, \
(nettle_cipher_func *) (encrypt), \
(nettle_cipher_func *) (encrypt), \
(length), (digest)))
(length), (digest)))
...
...
This diff is collapsed.
Click to expand it.
testsuite/cmac-test.c
+
16
−
15
View file @
69208ec1
...
@@ -2,23 +2,24 @@
...
@@ -2,23 +2,24 @@
#include
"nettle-internal.h"
#include
"nettle-internal.h"
#include
"cmac.h"
#include
"cmac.h"
typedef
void
set_key_func
(
void
*
ctx
,
const
uint8_t
*
key
);
typedef
void
update_func
(
void
*
ctx
,
size_t
length
,
const
uint8_t
*
data
);
typedef
void
digest_func
(
void
*
ctx
,
size_t
length
,
uint8_t
*
digest
);
#define test_cmac_aes128(key, msg, ref) \
#define test_cmac_aes128(key, msg, ref) \
test_cmac_hash ((set_key_func*)cmac_aes128_set_key, (update_func*)cmac_aes128_update, \
test_cmac_hash ((nettle_set_key_func*) cmac_aes128_set_key, \
(digest_func*)cmac_aes128_digest, sizeof(struct cmac_aes128_ctx), \
(nettle_hash_update_func*) cmac_aes128_update, \
(nettle_hash_digest_func*) cmac_aes128_digest, \
sizeof(struct cmac_aes128_ctx), \
key, msg, ref)
key, msg, ref)
#define test_cmac_aes256(key, msg, ref) \
#define test_cmac_aes256(key, msg, ref) \
test_cmac_hash ((set_key_func*)cmac_aes256_set_key, (update_func*)cmac_aes256_update, \
test_cmac_hash ((nettle_set_key_func*) cmac_aes256_set_key, \
(digest_func*)cmac_aes256_digest, sizeof(struct cmac_aes256_ctx), \
(nettle_hash_update_func*) cmac_aes256_update, \
(nettle_hash_digest_func*) cmac_aes256_digest, \
sizeof(struct cmac_aes256_ctx), \
key, msg, ref)
key, msg, ref)
static
void
static
void
test_cmac_hash
(
set_key_func
*
set_key
,
update_func
*
update
,
test_cmac_hash
(
nettle_set_key_func
*
set_key
,
digest_func
*
digest
,
size_t
ctx_size
,
nettle_hash_update_func
*
update
,
nettle_hash_digest_func
*
digest
,
size_t
ctx_size
,
const
struct
tstring
*
key
,
const
struct
tstring
*
msg
,
const
struct
tstring
*
key
,
const
struct
tstring
*
msg
,
const
struct
tstring
*
ref
)
const
struct
tstring
*
ref
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment