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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitry Baryshkov
nettle
Commits
97829771
Commit
97829771
authored
23 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
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
4fc40778
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile.am
+1
-0
1 addition, 0 deletions
Makefile.am
cbc.c
+17
-2
17 additions, 2 deletions
cbc.c
cbc.h
+8
-1
8 additions, 1 deletion
cbc.h
with
26 additions
and
3 deletions
Makefile.am
+
1
−
0
View file @
97829771
...
@@ -12,6 +12,7 @@ libnettleinclude_HEADERS = aes.h arcfour.h blowfish.h cast128.h des.h \
...
@@ -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
\
libnettle_a_SOURCES
=
aes.c aes.h arcfour.c arcfour.h
\
cast128.c cast128.h cast128_sboxes.h
\
cast128.c cast128.h cast128_sboxes.h
\
blowfish.h blowfish.c
\
blowfish.h blowfish.c
\
cbc.c
\
des.c des.h desinfo.h desCode.h
\
des.c des.h desinfo.h desCode.h
\
md5.c md5.h md5-compat.c md5-compat.h
\
md5.c md5.h md5-compat.c md5-compat.h
\
sha1.c sha1.h
\
sha1.c sha1.h
\
...
...
This diff is collapsed.
Click to expand it.
cbc.c
+
17
−
2
View file @
97829771
...
@@ -25,7 +25,11 @@
...
@@ -25,7 +25,11 @@
#include
"cbc.h"
#include
"cbc.h"
#include
"memxor.h"
#include
<assert.h>
#include
<assert.h>
#include
<stdlib.h>
#include
<string.h>
void
void
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
...
@@ -40,7 +44,7 @@ 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
)
for
(
;
length
;
length
-=
block_size
,
src
+=
block_size
,
dst
+=
block_size
)
{
{
memxor
(
iv
,
src
,
block_size
);
memxor
(
iv
,
src
,
block_size
);
f
(
ctx
,
dst
,
src
,
block_size
);
f
(
ctx
,
block_size
,
dst
,
src
);
memcpy
(
iv
,
dst
,
block_size
);
memcpy
(
iv
,
dst
,
block_size
);
}
}
}
}
...
@@ -69,10 +73,21 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
...
@@ -69,10 +73,21 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
}
}
/* Decrypt in ECB mode */
/* Decrypt in ECB mode */
f
(
ctx
,
dst
,
src
,
length
);
f
(
ctx
,
length
,
dst
,
src
);
/* XOR the cryptotext, shifted one block */
/* XOR the cryptotext, shifted one block */
memxor
(
dst
,
iv
,
block_size
);
memxor
(
dst
,
iv
,
block_size
);
memxor
(
dst
+
block_size
,
src
,
length
-
block_size
);
memxor
(
dst
+
block_size
,
src
,
length
-
block_size
);
memcpy
(
iv
,
src
+
length
-
block_size
,
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
);
}
This diff is collapsed.
Click to expand it.
cbc.h
+
8
−
1
View file @
97829771
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#include
<inttypes.h>
#include
<inttypes.h>
/* Uses a void * for cipher contexts.
It's hard to be type safe.
*/
/* Uses a void * for cipher contexts. */
void
void
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
cbc_encrypt
(
void
*
ctx
,
void
(
*
f
)(
void
*
ctx
,
...
@@ -46,4 +46,11 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
...
@@ -46,4 +46,11 @@ cbc_decrypt(void *ctx, void (*f)(void *ctx,
unsigned
length
,
uint8_t
*
dst
,
unsigned
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
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 */
#endif
/* NETTLE_CBC_H_INCLUDED */
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