Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
4e7b08f6
Commit
4e7b08f6
authored
Sep 07, 2001
by
Niels Möller
Browse files
Work-in-progress.
Rev: src/nettle/Makefile.am:1.12 Rev: src/nettle/cbc.c:1.2 Rev: src/nettle/cbc.h:1.2
parent
5d748646
Changes
3
Show whitespace changes
Inline
Side-by-side
src/nettle/Makefile.am
View file @
4e7b08f6
...
...
@@ -12,6 +12,7 @@ libnettleinclude_HEADERS = aes.h arcfour.h blowfish.h cast128.h des.h \
libnettle_a_SOURCES
=
aes.c aes.h arcfour.c arcfour.h
\
cast128.c cast128.h cast128_sboxes.h
\
blowfish.h blowfish.c
\
cbc.c
\
des.c des.h desinfo.h desCode.h
\
md5.c md5.h md5-compat.c md5-compat.h
\
sha1.c sha1.h
\
...
...
src/nettle/cbc.c
View file @
4e7b08f6
...
...
@@ -25,7 +25,11 @@
#include "cbc.h"
#include "memxor.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
...
...
@@ -40,7 +44,7 @@ cbc_encrypt(void *ctx, void (*f)(void *ctx,
for
(
;
length
;
length
-=
block_size
,
src
+=
block_size
,
dst
+=
block_size
)
{
memxor
(
iv
,
src
,
block_size
);
f
(
ctx
,
dst
,
src
,
block_size
);
f
(
ctx
,
block_size
,
dst
,
src
);
memcpy
(
iv
,
dst
,
block_size
);
}
}
...
...
@@ -69,10 +73,21 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
}
/* Decrypt in ECB mode */
f
(
ctx
,
dst
,
src
,
length
);
f
(
ctx
,
length
,
dst
,
src
);
/* XOR the cryptotext, shifted one block */
memxor
(
dst
,
iv
,
block_size
);
memxor
(
dst
+
block_size
,
src
,
length
-
block_size
);
memcpy
(
iv
,
src
+
length
-
block_size
,
block_size
);
}
#include "des.h"
static
void
foo
(
void
)
{
struct
des_ctx
ctx
;
uint8_t
iv
[
DES_BLOCK_SIZE
];
uint8_t
src
[
DES_BLOCK_SIZE
];
uint8_t
dst
[
DES_BLOCK_SIZE
];
CBC_ENCRYPT
(
&
ctx
,
des_encrypt
,
DES_BLOCK_SIZE
,
iv
,
DES_BLOCK_SIZE
,
dst
,
src
);
}
src/nettle/cbc.h
View file @
4e7b08f6
...
...
@@ -28,7 +28,7 @@
#include <inttypes.h>
/* Uses a void * for cipher contexts.
It's hard to be type safe.
*/
/* Uses a void * for cipher contexts. */
void
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
...
...
@@ -46,4 +46,11 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
unsigned
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
/* Type safer variants */
#define CBC_ENCRYPT(ctx, f, b, iv, l, dst, src) \
(0 ? ((f)((ctx),0,NULL,NULL)) \
: cbc_encrypt((void *)(ctx), \
((*)(void *, unsigned, uint8_t *, const uint8_t *)) (f), \
(b), (iv), (l), (dst), (src)))
#endif
/* NETTLE_CBC_H_INCLUDED */
Write
Preview
Supports
Markdown
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