Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
candidates
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
017a9cea
authored
Sep 26, 2020
by
Hongjun Wu
Committed by
Sebastian Renner
Sep 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tinyjambu with for loop
parent
109ff80f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
189 additions
and
199 deletions
+189
-199
tinyjambu/Implementations/crypto_aead/tinyjambu128/opt/encrypt.c
+0
-0
tinyjambu/Implementations/crypto_aead/tinyjambu128/ref/encrypt.c
+122
-124
tinyjambu/Implementations/crypto_aead/tinyjambu192/opt/encrypt.c
+3
-5
tinyjambu/Implementations/crypto_aead/tinyjambu192/ref/encrypt.c
+26
-28
tinyjambu/Implementations/crypto_aead/tinyjambu256/opt/encrypt.c
+13
-15
tinyjambu/Implementations/crypto_aead/tinyjambu256/ref/encrypt.c
+25
-27
No files found.
tinyjambu/Implementations/crypto_aead/tinyjambu128/opt/encrypt.c
View file @
017a9cea
This diff is collapsed.
Click to expand it.
tinyjambu/Implementations/crypto_aead/tinyjambu128/ref/encrypt.c
View file @
017a9cea
This diff is collapsed.
Click to expand it.
tinyjambu/Implementations/crypto_aead/tinyjambu192/opt/encrypt.c
View file @
017a9cea
/*
TinyJAMBU-192: 192-bit key, 96-bit IV
Optimized Implementation for 32-bit processor
Optimized Implementation for 32-bit processor
The state consists of four 32-bit registers
state[3] || state[2] || state[1] || state[0]
Implemented by Hongjun Wu
Implemented by Hongjun Wu
*/
#include <string.h>
#include <stdio.h>
#include "crypto_aead.h"
#define FrameBitsIV 0x10
...
...
@@ -165,7 +163,7 @@ int crypto_aead_encrypt(
((
unsigned
int
*
)
mac
)[
1
]
=
state
[
2
];
*
clen
=
mlen
+
8
;
memcpy
(
c
+
mlen
,
mac
,
8
);
for
(
j
=
0
;
j
<
8
;
j
++
)
c
[
mlen
+
j
]
=
mac
[
j
];
return
0
;
}
...
...
tinyjambu/Implementations/crypto_aead/tinyjambu192/ref/encrypt.c
View file @
017a9cea
/*
TinyJAMBU: 192-bit key, 96-bit IV
Reference implementation for 32-bit CPU
Reference implementation for 32-bit CPU
The state consists of four 32-bit registers
state[3] || state[2] || state[1] || state[0]
Implemented by: Hongjun Wu
Implemented by: Hongjun Wu
*/
#include <string.h>
#include <stdio.h>
#include "crypto_aead.h"
#define FrameBitsIV 0x10
...
...
@@ -42,21 +40,21 @@ void state_update(unsigned int *state, const unsigned char *key, unsigned int nu
/* The input to initialization is the 192-bit key; 96-bit IV;*/
void
initialization
(
const
unsigned
char
*
key
,
const
unsigned
char
*
iv
,
unsigned
int
*
state
)
{
int
i
;
int
i
;
//initialize the state as 0
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
//initialize the state as 0
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//introduce IV into the state
for
(
i
=
0
;
i
<
3
;
i
++
)
{
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
//introduce IV into the state
for
(
i
=
0
;
i
<
3
;
i
++
)
{
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
}
//process the associated data
...
...
@@ -92,15 +90,15 @@ int crypto_aead_encrypt(
const
unsigned
char
*
k
)
{
unsigned
long
long
i
;
unsigned
long
long
i
;
unsigned
int
j
;
unsigned
char
mac
[
8
];
unsigned
int
state
[
4
];
unsigned
char
mac
[
8
];
unsigned
int
state
[
4
];
//initialization stage
initialization
(
k
,
npub
,
state
);
//initialization stage
initialization
(
k
,
npub
,
state
);
//process the associated data
//process the associated data
process_ad
(
k
,
ad
,
adlen
,
state
);
//process the plaintext
...
...
@@ -133,10 +131,10 @@ int crypto_aead_encrypt(
state_update
(
state
,
k
,
NROUND1
);
((
unsigned
int
*
)
mac
)[
1
]
=
state
[
2
];
*
clen
=
mlen
+
8
;
memcpy
(
c
+
mlen
,
mac
,
8
)
;
*
clen
=
mlen
+
8
;
for
(
j
=
0
;
j
<
8
;
j
++
)
c
[
mlen
+
j
]
=
mac
[
j
]
;
return
0
;
return
0
;
}
//decrypt a message
...
...
@@ -195,6 +193,6 @@ int crypto_aead_decrypt(
//verification of the authentication tag
for
(
j
=
0
;
j
<
8
;
j
++
)
{
check
|=
(
mac
[
j
]
^
c
[
clen
-
8
+
j
]);
}
if
(
check
==
0
)
return
0
;
else
return
-
1
;
if
(
check
==
0
)
return
0
;
else
return
-
1
;
}
tinyjambu/Implementations/crypto_aead/tinyjambu256/opt/encrypt.c
View file @
017a9cea
/*
TinyJAMBU-256: 256-bit key, 96-bit IV
Optimized implementation
Optimized implementation
The state consists of four 32-bit registers
state[3] || state[2] || state[1] || state[0]
Implemented by: Hongjun Wu
Implemented by: Hongjun Wu
*/
#include <string.h>
#include <stdio.h>
#include "crypto_aead.h"
#define FrameBitsIV 0x10
...
...
@@ -61,18 +59,18 @@ void initialization(const unsigned char *key, const unsigned char *iv, unsigned
int
i
;
//initialize the state as 0
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//introduce IV into the state
//introduce IV into the state
for
(
i
=
0
;
i
<
3
;
i
++
)
{
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
}
//process the associated data
...
...
@@ -150,8 +148,8 @@ int crypto_aead_encrypt(
((
unsigned
int
*
)
mac
)[
1
]
=
state
[
2
];
*
clen
=
mlen
+
8
;
memcpy
(
c
+
mlen
,
mac
,
8
)
;
for
(
j
=
0
;
j
<
8
;
j
++
)
c
[
mlen
+
j
]
=
mac
[
j
]
;
return
0
;
}
...
...
tinyjambu/Implementations/crypto_aead/tinyjambu256/ref/encrypt.c
View file @
017a9cea
/*
TinyJAMBU-256: 256-bit key, 96-bit IV
Reference Implementation for 32-bit processor
Reference Implementation for 32-bit processor
The state consists of four 32-bit registers
state[3] || state[2] || state[1] || state[0]
Implemented by Hongjun Wu
Implemented by Hongjun Wu
*/
#include <string.h>
#include <stdio.h>
#include "crypto_aead.h"
#define FrameBitsIV 0x10
...
...
@@ -42,21 +40,21 @@ void state_update(unsigned int *state, const unsigned char *key, unsigned int nu
/* The input to initialization is the 128-bit key; 96-bit IV;*/
void
initialization
(
const
unsigned
char
*
key
,
const
unsigned
char
*
iv
,
unsigned
int
*
state
)
{
int
i
;
int
i
;
//initialize the state as 0
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
//initialize the state as 0
for
(
i
=
0
;
i
<
4
;
i
++
)
state
[
i
]
=
0
;
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//update the state with the key
state_update
(
state
,
key
,
NROUND2
);
//introduce IV into the state
for
(
i
=
0
;
i
<
3
;
i
++
)
{
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
//introduce IV into the state
for
(
i
=
0
;
i
<
3
;
i
++
)
{
state
[
1
]
^=
FrameBitsIV
;
state_update
(
state
,
key
,
NROUND1
);
state
[
3
]
^=
((
unsigned
int
*
)
iv
)[
i
];
}
}
//process the associated data
...
...
@@ -92,15 +90,15 @@ int crypto_aead_encrypt(
const
unsigned
char
*
k
)
{
unsigned
long
long
i
;
unsigned
long
long
i
;
unsigned
int
j
;
unsigned
char
mac
[
8
];
unsigned
int
state
[
4
];
unsigned
char
mac
[
8
];
unsigned
int
state
[
4
];
//initialization stage
initialization
(
k
,
npub
,
state
);
//initialization stage
initialization
(
k
,
npub
,
state
);
//process the associated data
//process the associated data
process_ad
(
k
,
ad
,
adlen
,
state
);
//process the plaintext
...
...
@@ -133,10 +131,10 @@ int crypto_aead_encrypt(
state_update
(
state
,
k
,
NROUND1
);
((
unsigned
int
*
)
mac
)[
1
]
=
state
[
2
];
*
clen
=
mlen
+
8
;
memcpy
(
c
+
mlen
,
mac
,
8
);
*
clen
=
mlen
+
8
;
for
(
j
=
0
;
j
<
8
;
j
++
)
c
[
mlen
+
j
]
=
mac
[
j
];
return
0
;
return
0
;
}
//decrypt a message
...
...
@@ -194,6 +192,6 @@ int crypto_aead_decrypt(
//verification of the authentication tag
for
(
j
=
0
;
j
<
8
;
j
++
)
{
check
|=
(
mac
[
j
]
^
c
[
clen
-
8
+
j
]);
}
if
(
check
==
0
)
return
0
;
else
return
-
1
;
if
(
check
==
0
)
return
0
;
else
return
-
1
;
}
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