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
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Dmitry Baryshkov
nettle
Commits
588e0e8f
Commit
588e0e8f
authored
Mar 31, 2012
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
New salsa20 constants.
parent
a33775b0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ChangeLog
+4
-0
4 additions, 0 deletions
ChangeLog
salsa20.c
+13
-13
13 additions, 13 deletions
salsa20.c
salsa20.h
+13
-1
13 additions, 1 deletion
salsa20.h
with
30 additions
and
14 deletions
ChangeLog
+
4
−
0
View file @
588e0e8f
2012-03-31 Niels Möller <nisse@lysator.liu.se>
2012-03-31 Niels Möller <nisse@lysator.liu.se>
* salsa20.h (SALSA20_BLOCK_SIZE): New constant.
(_SALSA20_INPUT_LENGTH): New constant.
* salsa20.c: Use these constants.
* salsa20.c (ROTL32): Deleted macro, use the one from macros.h
* salsa20.c (ROTL32): Deleted macro, use the one from macros.h
instead, with reversed order of arguments.
instead, with reversed order of arguments.
(ROTATE, XOR, PLUS, PLUSONE): Deleted macros, use ROTL32 and
(ROTATE, XOR, PLUS, PLUSONE): Deleted macros, use ROTL32 and
...
...
This diff is collapsed.
Click to expand it.
salsa20.c
+
13
−
13
View file @
588e0e8f
...
@@ -52,12 +52,12 @@
...
@@ -52,12 +52,12 @@
#define U8TO32_LITTLE(p) U32TO32_LITTLE(((uint32_t*)(p))[0])
#define U8TO32_LITTLE(p) U32TO32_LITTLE(((uint32_t*)(p))[0])
#define U32TO8_LITTLE(p, v) (((uint32_t*)(p))[0] = U32TO32_LITTLE(v))
#define U32TO8_LITTLE(p, v) (((uint32_t*)(p))[0] = U32TO32_LITTLE(v))
static
void
salsa20_wordtobyte
(
uint8_t
output
[
64
],
const
uint32_t
input
[
16
])
static
void
salsa20_wordtobyte
(
uint8_t
output
[
SALSA20_BLOCK_SIZE
],
const
uint32_t
input
[
_SALSA20_INPUT_LENGTH
])
{
{
uint32_t
x
[
16
];
uint32_t
x
[
_SALSA20_INPUT_LENGTH
];
int
i
;
int
i
;
for
(
i
=
0
;
i
<
16
;
++
i
)
x
[
i
]
=
input
[
i
];
for
(
i
=
0
;
i
<
_SALSA20_INPUT_LENGTH
;
++
i
)
x
[
i
]
=
input
[
i
];
for
(
i
=
20
;
i
>
0
;
i
-=
2
)
{
for
(
i
=
20
;
i
>
0
;
i
-=
2
)
{
x
[
4
]
^=
ROTL32
(
7
,
x
[
0
]
+
x
[
12
]);
x
[
4
]
^=
ROTL32
(
7
,
x
[
0
]
+
x
[
12
]);
x
[
8
]
^=
ROTL32
(
9
,
x
[
4
]
+
x
[
0
]);
x
[
8
]
^=
ROTL32
(
9
,
x
[
4
]
+
x
[
0
]);
...
@@ -92,12 +92,12 @@ static void salsa20_wordtobyte(uint8_t output[64],const uint32_t input[16])
...
@@ -92,12 +92,12 @@ static void salsa20_wordtobyte(uint8_t output[64],const uint32_t input[16])
x
[
14
]
^=
ROTL32
(
13
,
x
[
13
]
+
x
[
12
]);
x
[
14
]
^=
ROTL32
(
13
,
x
[
13
]
+
x
[
12
]);
x
[
15
]
^=
ROTL32
(
18
,
x
[
14
]
+
x
[
13
]);
x
[
15
]
^=
ROTL32
(
18
,
x
[
14
]
+
x
[
13
]);
}
}
for
(
i
=
0
;
i
<
16
;
++
i
)
x
[
i
]
=
x
[
i
]
+
input
[
i
];
for
(
i
=
0
;
i
<
_SALSA20_INPUT_LENGTH
;
++
i
)
x
[
i
]
=
x
[
i
]
+
input
[
i
];
for
(
i
=
0
;
i
<
16
;
++
i
)
U32TO8_LITTLE
(
output
+
4
*
i
,
x
[
i
]);
for
(
i
=
0
;
i
<
_SALSA20_INPUT_LENGTH
;
++
i
)
U32TO8_LITTLE
(
output
+
4
*
i
,
x
[
i
]);
}
}
static
const
char
sigma
[
16
]
=
"expand 32-byte k"
;
static
const
char
sigma
[
_SALSA20_INPUT_LENGTH
]
=
"expand 32-byte k"
;
static
const
char
tau
[
16
]
=
"expand 16-byte k"
;
static
const
char
tau
[
_SALSA20_INPUT_LENGTH
]
=
"expand 16-byte k"
;
void
void
salsa20_set_key
(
struct
salsa20_ctx
*
ctx
,
salsa20_set_key
(
struct
salsa20_ctx
*
ctx
,
...
@@ -144,7 +144,7 @@ salsa20_crypt(struct salsa20_ctx *ctx,
...
@@ -144,7 +144,7 @@ salsa20_crypt(struct salsa20_ctx *ctx,
uint8_t
*
c
,
uint8_t
*
c
,
const
uint8_t
*
m
)
const
uint8_t
*
m
)
{
{
uint8_t
output
[
64
];
uint8_t
output
[
SALSA20_BLOCK_SIZE
];
unsigned
i
;
unsigned
i
;
if
(
!
length
)
return
;
if
(
!
length
)
return
;
...
@@ -155,13 +155,13 @@ salsa20_crypt(struct salsa20_ctx *ctx,
...
@@ -155,13 +155,13 @@ salsa20_crypt(struct salsa20_ctx *ctx,
ctx
->
input
[
9
]
++
;
ctx
->
input
[
9
]
++
;
/* stopping at 2^70 length per nonce is user's responsibility */
/* stopping at 2^70 length per nonce is user's responsibility */
}
}
if
(
length
<=
64
)
{
if
(
length
<=
SALSA20_BLOCK_SIZE
)
{
for
(
i
=
0
;
i
<
length
;
++
i
)
c
[
i
]
=
m
[
i
]
^
output
[
i
];
for
(
i
=
0
;
i
<
length
;
++
i
)
c
[
i
]
=
m
[
i
]
^
output
[
i
];
return
;
return
;
}
}
for
(
i
=
0
;
i
<
64
;
++
i
)
c
[
i
]
=
m
[
i
]
^
output
[
i
];
for
(
i
=
0
;
i
<
SALSA20_BLOCK_SIZE
;
++
i
)
c
[
i
]
=
m
[
i
]
^
output
[
i
];
length
-=
64
;
length
-=
SALSA20_BLOCK_SIZE
;
c
+=
64
;
c
+=
SALSA20_BLOCK_SIZE
;
m
+=
64
;
m
+=
SALSA20_BLOCK_SIZE
;
}
}
}
}
This diff is collapsed.
Click to expand it.
salsa20.h
+
13
−
1
View file @
588e0e8f
...
@@ -43,12 +43,24 @@ extern "C" {
...
@@ -43,12 +43,24 @@ extern "C" {
#define SALSA20_MIN_KEY_SIZE 16
#define SALSA20_MIN_KEY_SIZE 16
#define SALSA20_MAX_KEY_SIZE 32
#define SALSA20_MAX_KEY_SIZE 32
#define SALSA20_KEY_SIZE 32
#define SALSA20_KEY_SIZE 32
#define SALSA20_BLOCK_SIZE 64
#define SALSA20_IV_SIZE 8
#define SALSA20_IV_SIZE 8
#define _SALSA20_INPUT_LENGTH 16
struct
salsa20_ctx
struct
salsa20_ctx
{
{
uint32_t
input
[
16
];
/* Indices 1-4 and 11-14 holds the key (two identical copies for the
shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
are the IV, and indices 8, 9 are the block counter:
C K K K
K C I I
B B C K
K K K C
*/
uint32_t
input
[
_SALSA20_INPUT_LENGTH
];
};
};
void
void
...
...
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