Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
92460565
authored
Jul 17, 2019
by
Sebastian Renner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on GCM
parent
4c3abfbd
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
8 deletions
+16
-8
compile_all.py
+1
-1
mbed_aes_gcm/LWC_AEAD_KAT_128_96.txt
+0
-0
mbed_aes_gcm/api.h
+1
-1
mbed_aes_gcm/gcm.c
+12
-3
mbed_aes_gcm/genkat_aead.c
+2
-3
No files found.
compile_all.py
View file @
92460565
...
@@ -156,7 +156,7 @@ def main(argv):
...
@@ -156,7 +156,7 @@ def main(argv):
try
:
try
:
b
=
build
(
d
,
template_dir
)
b
=
build
(
d
,
template_dir
)
test_script
.
write
(
"echo
\"
TESTING
%
s
\"\n
"
%
d
)
test_script
.
write
(
"echo
\"
TESTING
%
s
\"\n
"
%
d
)
test_script
.
write
(
"./test.py
%
s
%
s 2>
%
s | tee
%
s
\n
"
%
(
test_script
.
write
(
"./test.py
%
s
%
s 2>
%
s | tee
%
s
\n
"
%
t
,
t
,
os
.
path
.
join
(
b
,
'test'
),
os
.
path
.
join
(
b
,
'test'
),
os
.
path
.
join
(
b
,
'test_stderr.log'
),
os
.
path
.
join
(
b
,
'test_stderr.log'
),
...
...
mbed_aes_gcm/LWC_AEAD_KAT_128_96.txt
View file @
92460565
This source diff could not be displayed because it is too large. You can
view the blob
instead.
mbed_aes_gcm/api.h
View file @
92460565
#define CRYPTO_KEYBYTES 16
#define CRYPTO_KEYBYTES 16
#define CRYPTO_NSECBYTES 0
#define CRYPTO_NSECBYTES 0
#define CRYPTO_NPUBBYTES 12
#define CRYPTO_NPUBBYTES 12
#define CRYPTO_ABYTES
0
#define CRYPTO_ABYTES
16
#define CRYPTO_NOOVERLAP 1
#define CRYPTO_NOOVERLAP 1
mbed_aes_gcm/gcm.c
View file @
92460565
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#if defined(MBEDTLS_GCM_C)
#if defined(MBEDTLS_GCM_C)
#include "gcm.h"
#include "gcm.h"
#include "api.h"
#include "crypto_aead.h"
#include "crypto_aead.h"
#include "platform_util.h"
#include "platform_util.h"
...
@@ -87,7 +88,6 @@
...
@@ -87,7 +88,6 @@
}
}
#endif
#endif
unsigned
char
tag_buf
[
16
];
/*
/*
...
@@ -113,12 +113,16 @@ int crypto_aead_encrypt(
...
@@ -113,12 +113,16 @@ int crypto_aead_encrypt(
{
{
mbedtls_gcm_context
ctx
;
mbedtls_gcm_context
ctx
;
int
ret
;
int
ret
;
unsigned
long
long
mask
=
15
;
unsigned
long
long
mlenp
=
(
mlen
+
mask
)
&
(
~
mask
);
unsigned
char
tag_buf
[
CRYPTO_ABYTES
];
*
clen
=
mlenp
+
CRYPTO_ABYTES
;
mbedtls_gcm_init
(
&
ctx
);
mbedtls_gcm_init
(
&
ctx
);
ret
=
mbedtls_gcm_setkey
(
&
ctx
,
MBEDTLS_CIPHER_ID_AES
,
k
,
128
);
ret
=
mbedtls_gcm_setkey
(
&
ctx
,
MBEDTLS_CIPHER_ID_AES
,
k
,
128
);
ret
=
mbedtls_gcm_crypt_and_tag
(
&
ctx
,
1
,
mlen
,
npub
,
12
,
ad
,
adlen
,
m
,
c
,
16
,
tag_buf
);
ret
=
mbedtls_gcm_crypt_and_tag
(
&
ctx
,
1
,
mlen
,
npub
,
12
,
ad
,
adlen
,
m
,
c
,
16
,
tag_buf
);
mbedtls_gcm_free
(
&
ctx
);
mbedtls_gcm_free
(
&
ctx
);
memcpy
(
c
+
mlenp
,
tag_buf
,
CRYPTO_ABYTES
);
return
ret
;
return
ret
;
}
}
...
@@ -133,6 +137,11 @@ int crypto_aead_decrypt(
...
@@ -133,6 +137,11 @@ int crypto_aead_decrypt(
{
{
mbedtls_gcm_context
ctx
;
mbedtls_gcm_context
ctx
;
int
ret
;
int
ret
;
unsigned
char
tag_buf
[
CRYPTO_ABYTES
];
clen
-=
CRYPTO_ABYTES
;
memcpy
(
tag_buf
,
c
+
clen
,
CRYPTO_ABYTES
);
*
mlen
=
clen
;
mbedtls_gcm_init
(
&
ctx
);
mbedtls_gcm_init
(
&
ctx
);
ret
=
mbedtls_gcm_setkey
(
&
ctx
,
MBEDTLS_CIPHER_ID_AES
,
k
,
128
);
ret
=
mbedtls_gcm_setkey
(
&
ctx
,
MBEDTLS_CIPHER_ID_AES
,
k
,
128
);
...
@@ -830,7 +839,7 @@ int mbedtls_gcm_self_test( int verbose )
...
@@ -830,7 +839,7 @@ int mbedtls_gcm_self_test( int verbose )
{
{
mbedtls_gcm_context
ctx
;
mbedtls_gcm_context
ctx
;
unsigned
char
buf
[
64
];
unsigned
char
buf
[
64
];
//unsigned char tag_buf[16
];
unsigned
char
tag_buf
[
CRYPTO_ABYTES
];
int
i
,
j
,
ret
;
int
i
,
j
,
ret
;
mbedtls_cipher_id_t
cipher
=
MBEDTLS_CIPHER_ID_AES
;
mbedtls_cipher_id_t
cipher
=
MBEDTLS_CIPHER_ID_AES
;
...
...
mbed_aes_gcm/genkat_aead.c
View file @
92460565
...
@@ -84,7 +84,6 @@ int generate_test_vectors()
...
@@ -84,7 +84,6 @@ int generate_test_vectors()
init_buffer
(
nonce
,
sizeof
(
nonce
));
init_buffer
(
nonce
,
sizeof
(
nonce
));
init_buffer
(
msg
,
sizeof
(
msg
));
init_buffer
(
msg
,
sizeof
(
msg
));
init_buffer
(
ad
,
sizeof
(
ad
));
init_buffer
(
ad
,
sizeof
(
ad
));
init_buffer
(
ct
,
sizeof
(
ct
));
sprintf
(
fileName
,
"LWC_AEAD_KAT_%d_%d.txt"
,
(
CRYPTO_KEYBYTES
*
8
),
(
CRYPTO_NPUBBYTES
*
8
));
sprintf
(
fileName
,
"LWC_AEAD_KAT_%d_%d.txt"
,
(
CRYPTO_KEYBYTES
*
8
),
(
CRYPTO_NPUBBYTES
*
8
));
...
@@ -97,7 +96,6 @@ int generate_test_vectors()
...
@@ -97,7 +96,6 @@ int generate_test_vectors()
for
(
unsigned
long
long
adlen
=
0
;
adlen
<=
MAX_ASSOCIATED_DATA_LENGTH
;
adlen
++
)
{
for
(
unsigned
long
long
adlen
=
0
;
adlen
<=
MAX_ASSOCIATED_DATA_LENGTH
;
adlen
++
)
{
clen
=
mlen
;
fprintf
(
fp
,
"Count = %d
\n
"
,
count
++
);
fprintf
(
fp
,
"Count = %d
\n
"
,
count
++
);
...
@@ -119,10 +117,11 @@ int generate_test_vectors()
...
@@ -119,10 +117,11 @@ int generate_test_vectors()
fprintf
(
fp
,
"
\n
"
);
fprintf
(
fp
,
"
\n
"
);
mlen2
=
clen
;
if
((
func_ret
=
crypto_aead_decrypt
(
msg2
,
&
mlen2
,
NULL
,
ct
,
clen
,
ad
,
adlen
,
nonce
,
key
))
!=
0
)
{
if
((
func_ret
=
crypto_aead_decrypt
(
msg2
,
&
mlen2
,
NULL
,
ct
,
clen
,
ad
,
adlen
,
nonce
,
key
))
!=
0
)
{
fprintf
(
fp
,
"crypto_aead_decrypt returned <%d>
\n
"
,
func_ret
);
fprintf
(
fp
,
"crypto_aead_decrypt returned <%d>
\n
"
,
func_ret
);
ret_val
=
KAT_CRYPTO_FAILURE
;
ret_val
=
KAT_CRYPTO_FAILURE
;
fprint_bstr
(
fp
,
"PT = "
,
msg2
,
mlen2
);
break
;
break
;
}
}
...
...
Write
Preview
Markdown
is supported
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