Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Nettle
nettle
Commits
aa546471
Commit
aa546471
authored
Mar 04, 2014
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed chacha256_set_key to chacha_set_key.
parent
626464da
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
89 deletions
+35
-89
ChangeLog
ChangeLog
+10
-0
Makefile.in
Makefile.in
+0
-1
chacha-poly1305.c
chacha-poly1305.c
+1
-1
chacha-set-key.c
chacha-set-key.c
+18
-9
chacha.h
chacha.h
+2
-10
chacha256-set-key.c
chacha256-set-key.c
+0
-65
nettle-internal.c
nettle-internal.c
+2
-2
testsuite/chacha-test.c
testsuite/chacha-test.c
+2
-1
No files found.
ChangeLog
View file @
aa546471
2014-03-04 Niels Möller <nisse@lysator.liu.se>
* Makefile.in (nettle_SOURCES): Deleted chacha128-set-key.c and
chacha256-set-key.c.
* chacha.h (CHACHA256_KEY_SIZE): Deleted.
(chacha_set_key): Updated prototype.
* chacha256-set-key.c (chacha256_set_key): Deleted file and
function, moved to...
* chacha-set-key.c (chacha_set_key): Do 256-bit keys only. Deleted
length argument. Updated all callers.
* chacha128-set-key.c (chacha128_set_key): Deleted file and
function. Support for 128-bit chacha keys may be reintroduced
later, if really needed.
...
...
Makefile.in
View file @
aa546471
...
...
@@ -90,7 +90,6 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
chacha-crypt.c chacha-core-internal.c
\
chacha-poly1305.c chacha-poly1305-meta.c
\
chacha-set-key.c chacha-set-nonce.c
\
chacha256-set-key.c
\
ctr.c des.c des3.c des-compat.c
\
eax.c eax-aes128.c eax-aes128-meta.c
\
gcm.c gcm-aes.c
\
...
...
chacha-poly1305.c
View file @
aa546471
...
...
@@ -40,7 +40,7 @@ void
chacha_poly1305_set_key
(
struct
chacha_poly1305_ctx
*
ctx
,
const
uint8_t
*
key
)
{
chacha
256
_set_key
(
&
ctx
->
chacha
,
key
);
chacha_set_key
(
&
ctx
->
chacha
,
key
);
}
void
...
...
chacha-set-key.c
View file @
aa546471
...
...
@@ -26,15 +26,24 @@
#include "chacha.h"
#include "macros.h"
void
chacha_set_key
(
struct
chacha_ctx
*
ctx
,
size_t
length
,
const
uint8_t
*
key
)
chacha_set_key
(
struct
chacha_ctx
*
ctx
,
const
uint8_t
*
key
)
{
switch
(
length
)
{
default:
abort
();
case
CHACHA256_KEY_SIZE
:
chacha256_set_key
(
ctx
,
key
);
break
;
}
static
const
uint32_t
sigma
[
4
]
=
{
/* "expand 32-byte k" */
0x61707865
,
0x3320646e
,
0x79622d32
,
0x6b206574
};
ctx
->
state
[
4
]
=
LE_READ_UINT32
(
key
+
0
);
ctx
->
state
[
5
]
=
LE_READ_UINT32
(
key
+
4
);
ctx
->
state
[
6
]
=
LE_READ_UINT32
(
key
+
8
);
ctx
->
state
[
7
]
=
LE_READ_UINT32
(
key
+
12
);
ctx
->
state
[
8
]
=
LE_READ_UINT32
(
key
+
16
);
ctx
->
state
[
9
]
=
LE_READ_UINT32
(
key
+
20
);
ctx
->
state
[
10
]
=
LE_READ_UINT32
(
key
+
24
);
ctx
->
state
[
11
]
=
LE_READ_UINT32
(
key
+
28
);
memcpy
(
ctx
->
state
,
sigma
,
sizeof
(
sigma
));
}
chacha.h
View file @
aa546471
...
...
@@ -37,17 +37,13 @@ extern "C" {
/* Name mangling */
#define chacha_set_key nettle_chacha_set_key
#define chacha256_set_key nettle_chacha256_set_key
#define chacha_set_nonce nettle_chacha_set_nonce
#define chacha_crypt nettle_chacha_crypt
#define _chacha_core _nettle_chacha_core
/* Possible keysizes, and a reasonable default. In octets. */
#define CHACHA256_KEY_SIZE 32
/* Currently, only 256-bit keys are supported. */
#define CHACHA_KEY_SIZE 32
#define CHACHA_BLOCK_SIZE 64
#define CHACHA_NONCE_SIZE 8
#define _CHACHA_STATE_LENGTH 16
...
...
@@ -69,11 +65,7 @@ struct chacha_ctx
};
void
chacha256_set_key
(
struct
chacha_ctx
*
ctx
,
const
uint8_t
*
key
);
void
chacha_set_key
(
struct
chacha_ctx
*
ctx
,
size_t
length
,
const
uint8_t
*
key
);
chacha_set_key
(
struct
chacha_ctx
*
ctx
,
const
uint8_t
*
key
);
void
chacha_set_nonce
(
struct
chacha_ctx
*
ctx
,
const
uint8_t
*
nonce
);
...
...
chacha256-set-key.c
deleted
100644 → 0
View file @
626464da
/* chacha256-set-key.c
*
* ChaCha key setup for 256-bit keys.
* Based on the Salsa20 implementation in Nettle.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Joachim Strömbergon
* Copyright (C) 2012 Simon Josefsson
* Copyright (C) 2012, 2014 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Based on:
ChaCha specification (doc id: 4027b5256e17b9796842e6d0f68b0b5e) and reference
implementation dated 2008.01.20
D. J. Bernstein
Public domain.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <string.h>
#include "chacha.h"
#include "macros.h"
void
chacha256_set_key
(
struct
chacha_ctx
*
ctx
,
const
uint8_t
*
key
)
{
static
const
uint32_t
sigma
[
4
]
=
{
/* "expand 32-byte k" */
0x61707865
,
0x3320646e
,
0x79622d32
,
0x6b206574
};
ctx
->
state
[
4
]
=
LE_READ_UINT32
(
key
+
0
);
ctx
->
state
[
5
]
=
LE_READ_UINT32
(
key
+
4
);
ctx
->
state
[
6
]
=
LE_READ_UINT32
(
key
+
8
);
ctx
->
state
[
7
]
=
LE_READ_UINT32
(
key
+
12
);
ctx
->
state
[
8
]
=
LE_READ_UINT32
(
key
+
16
);
ctx
->
state
[
9
]
=
LE_READ_UINT32
(
key
+
20
);
ctx
->
state
[
10
]
=
LE_READ_UINT32
(
key
+
24
);
ctx
->
state
[
11
]
=
LE_READ_UINT32
(
key
+
28
);
memcpy
(
ctx
->
state
,
sigma
,
sizeof
(
sigma
));
}
nettle-internal.c
View file @
aa546471
...
...
@@ -76,7 +76,7 @@ static void
chacha_set_key_hack
(
void
*
ctx
,
const
uint8_t
*
key
)
{
static
const
uint8_t
nonce
[
CHACHA_NONCE_SIZE
];
chacha
256
_set_key
(
ctx
,
key
);
chacha_set_key
(
ctx
,
key
);
chacha_set_nonce
(
ctx
,
nonce
);
}
...
...
@@ -84,7 +84,7 @@ chacha_set_key_hack(void *ctx, const uint8_t *key)
const
struct
nettle_cipher
nettle_chacha
=
{
"chacha"
,
sizeof
(
struct
chacha_ctx
),
0
,
CHACHA
256
_KEY_SIZE
,
0
,
CHACHA_KEY_SIZE
,
chacha_set_key_hack
,
chacha_set_key_hack
,
(
nettle_crypt_func
*
)
chacha_crypt
,
(
nettle_crypt_func
*
)
chacha_crypt
...
...
testsuite/chacha-test.c
View file @
aa546471
...
...
@@ -34,7 +34,8 @@ test_chacha(const struct tstring *key, const struct tstring *nonce,
{
struct
chacha_ctx
ctx
;
chacha_set_key
(
&
ctx
,
key
->
length
,
key
->
data
);
ASSERT
(
key
->
length
==
CHACHA_KEY_SIZE
);
chacha_set_key
(
&
ctx
,
key
->
data
);
ASSERT
(
nonce
->
length
==
CHACHA_NONCE_SIZE
);
if
(
rounds
==
20
)
...
...
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