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
23ef6e35
Commit
23ef6e35
authored
Feb 20, 2018
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RSA examples to use aes256_ctx, not the deprecated aes_ctx.
parent
24c73370
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
12 deletions
+23
-12
ChangeLog
ChangeLog
+11
-0
examples/rsa-decrypt.c
examples/rsa-decrypt.c
+3
-3
examples/rsa-encrypt.c
examples/rsa-encrypt.c
+3
-3
examples/rsa-session.h
examples/rsa-session.h
+6
-6
No files found.
ChangeLog
View file @
23ef6e35
2018-02-20 Niels Möller <nisse@lysator.liu.se>
* examples/rsa-session.h (struct rsa_session): Use struct
aes256_ctx, instead of the deprecated struct aes_ctx.
* examples/rsa-encrypt.c (rsa_session_set_encrypt_key)
(process_file): Use aes256_* functions.
* examples/rsa-decrypt.c (rsa_session_set_decrypt_key)
(process_file): Likewise.
2018-02-19 Niels Möller <nisse@lysator.liu.se>
* nettle-internal.h: Include sha3.h, needed for the definition of
...
...
examples/rsa-decrypt.c
View file @
23ef6e35
...
...
@@ -64,7 +64,7 @@ rsa_session_set_decrypt_key(struct rsa_session *ctx,
const
uint8_t
*
iv
=
SESSION_IV
(
key
);
const
uint8_t
*
hmac_key
=
SESSION_HMAC_KEY
(
key
);
aes_set_decrypt_key
(
&
ctx
->
aes
.
ctx
,
AES_KEY_SIZE
,
aes_key
);
aes
256
_set_decrypt_key
(
&
ctx
->
aes
.
ctx
,
aes_key
);
CBC_SET_IV
(
&
ctx
->
aes
,
iv
);
hmac_sha1_set_key
(
&
ctx
->
hmac
,
SHA1_DIGEST_SIZE
,
hmac_key
);
}
...
...
@@ -151,7 +151,7 @@ process_file(struct rsa_session *ctx,
if
(
size
)
{
CBC_DECRYPT
(
&
ctx
->
aes
,
aes_decrypt
,
size
,
buffer
,
buffer
);
CBC_DECRYPT
(
&
ctx
->
aes
,
aes
256
_decrypt
,
size
,
buffer
,
buffer
);
hmac_sha1_update
(
&
ctx
->
hmac
,
size
,
buffer
);
if
(
!
write_data
(
out
,
size
,
buffer
))
{
...
...
@@ -164,7 +164,7 @@ process_file(struct rsa_session *ctx,
while
(
size
==
BUF_SIZE
);
/* Decrypt final block */
CBC_DECRYPT
(
&
ctx
->
aes
,
aes_decrypt
,
AES_BLOCK_SIZE
,
buffer
,
buffer
);
CBC_DECRYPT
(
&
ctx
->
aes
,
aes
256
_decrypt
,
AES_BLOCK_SIZE
,
buffer
,
buffer
);
padding
=
buffer
[
AES_BLOCK_SIZE
-
1
];
if
(
padding
>
AES_BLOCK_SIZE
)
{
...
...
examples/rsa-encrypt.c
View file @
23ef6e35
...
...
@@ -63,7 +63,7 @@ rsa_session_set_encrypt_key(struct rsa_session *ctx,
const
uint8_t
*
iv
=
SESSION_IV
(
key
);
const
uint8_t
*
hmac_key
=
SESSION_HMAC_KEY
(
key
);
aes_set_encrypt_key
(
&
ctx
->
aes
.
ctx
,
AES_KEY_SIZE
,
aes_key
);
aes
256
_set_encrypt_key
(
&
ctx
->
aes
.
ctx
,
aes_key
);
CBC_SET_IV
(
&
ctx
->
aes
,
iv
);
hmac_sha1_set_key
(
&
ctx
->
hmac
,
SHA1_DIGEST_SIZE
,
hmac_key
);
}
...
...
@@ -136,7 +136,7 @@ process_file(struct rsa_session *ctx,
size
+=
padding
;
buffer
[
size
-
1
]
=
padding
;
CBC_ENCRYPT
(
&
ctx
->
aes
,
aes_encrypt
,
size
,
buffer
,
buffer
);
CBC_ENCRYPT
(
&
ctx
->
aes
,
aes
256
_encrypt
,
size
,
buffer
,
buffer
);
assert
(
size
+
SHA1_DIGEST_SIZE
<=
sizeof
(
buffer
));
...
...
@@ -151,7 +151,7 @@ process_file(struct rsa_session *ctx,
return
1
;
}
CBC_ENCRYPT
(
&
ctx
->
aes
,
aes_encrypt
,
size
,
buffer
,
buffer
);
CBC_ENCRYPT
(
&
ctx
->
aes
,
aes
256
_encrypt
,
size
,
buffer
,
buffer
);
if
(
!
write_data
(
out
,
size
,
buffer
))
{
werror
(
"Writing output failed: %s
\n
"
,
strerror
(
errno
));
...
...
examples/rsa-session.h
View file @
23ef6e35
...
...
@@ -25,10 +25,10 @@
uint8_t iv[AES_BLOCK_SIZE];
uint8_t hmac_key[SHA1_DIGEST_SIZE];
of size (4 + AES_KEY_SIZE + AES_BLOCK_SIZE + SHA1_DIGEST_SIZE) = 72
of size (4 + AES
256
_KEY_SIZE + AES_BLOCK_SIZE + SHA1_DIGEST_SIZE) = 72
bytes, encrypted using rsa-pkcs1.
The cleartext input is encrypted using aes-cbc. The final block is
The cleartext input is encrypted using aes
256
-cbc. The final block is
padded as
| data | random octets | padding length |
...
...
@@ -39,7 +39,7 @@
struct
rsa_session
{
struct
CBC_CTX
(
struct
aes_ctx
,
AES_BLOCK_SIZE
)
aes
;
struct
CBC_CTX
(
struct
aes
256
_ctx
,
AES_BLOCK_SIZE
)
aes
;
struct
hmac_sha1_ctx
hmac
;
struct
yarrow256_ctx
yarrow
;
};
...
...
@@ -47,13 +47,13 @@ struct rsa_session
struct
rsa_session_info
{
/* Version followed by aes key, iv and mac key */
uint8_t
key
[
4
+
AES_KEY_SIZE
+
AES_BLOCK_SIZE
+
SHA1_DIGEST_SIZE
];
uint8_t
key
[
4
+
AES
256
_KEY_SIZE
+
AES_BLOCK_SIZE
+
SHA1_DIGEST_SIZE
];
};
#define SESSION_VERSION(s) ((s)->key)
#define SESSION_AES_KEY(s) ((s)->key + 4)
#define SESSION_IV(s) ((s)->key + 4 + AES_KEY_SIZE)
#define SESSION_HMAC_KEY(s) ((s)->key + 4 + AES_KEY_SIZE + AES_BLOCK_SIZE)
#define SESSION_IV(s) ((s)->key + 4 + AES
256
_KEY_SIZE)
#define SESSION_HMAC_KEY(s) ((s)->key + 4 + AES
256
_KEY_SIZE + AES_BLOCK_SIZE)
void
rsa_session_set_encrypt_key
(
struct
rsa_session
*
ctx
,
...
...
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