Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
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
LSH
lsh
Commits
e01b15da
Commit
e01b15da
authored
Sep 10, 2001
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
(Cipher Block Chaining): This section more or less complete now.
Rev: src/nettle/nettle.texinfo:1.5
parent
87d91eb7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/nettle/nettle.texinfo
+56
-17
56 additions, 17 deletions
src/nettle/nettle.texinfo
with
56 additions
and
17 deletions
src/nettle/nettle.texinfo
+
56
−
17
View file @
e01b15da
...
@@ -296,6 +296,7 @@ This chapter describes all the Nettle functions, grouped by family.
...
@@ -296,6 +296,7 @@ This chapter describes all the Nettle functions, grouped by family.
@menu
@menu
* Hash functions::
* Hash functions::
* Cipher functions::
* Cipher functions::
* Cipher Block Chaining::
* Miscellaneous functions::
* Miscellaneous functions::
@end menu
@end menu
...
@@ -412,7 +413,7 @@ of the digest are written.
...
@@ -412,7 +413,7 @@ of the digest are written.
This functions doesn't change the state in any way.
This functions doesn't change the state in any way.
@end deftypefun
@end deftypefun
@node Cipher functions,
Miscellaneous functions
, Hash functions, Reference
@node Cipher functions,
Cipher Block Chaining
, Hash functions, Reference
@comment node-name, next, previous, up
@comment node-name, next, previous, up
@section Cipher functions
@section Cipher functions
...
@@ -441,7 +442,8 @@ However, using ECB is usually a bad idea. For a start, plaintext blocks
...
@@ -441,7 +442,8 @@ However, using ECB is usually a bad idea. For a start, plaintext blocks
that are equal are transformed to ciphertext blocks that are equal; that
that are equal are transformed to ciphertext blocks that are equal; that
leaks information about the plaintext. Usually you should apply the
leaks information about the plaintext. Usually you should apply the
cipher is some feedback mode, @dfn
{
CBC
}
(Cipher Block Chaining) being one
cipher is some feedback mode, @dfn
{
CBC
}
(Cipher Block Chaining) being one
of the most popular. XXX Add reference
of the most popular. @xref
{
Cipher Block Chaining
}
, for information on
how to apply CBC with Nettle.
A stream cipher can be used for messages of arbitrary length; a typical
A stream cipher can be used for messages of arbitrary length; a typical
stream cipher is a keyed pseudorandom generator. To encrypt a plaintext
stream cipher is a keyed pseudorandom generator. To encrypt a plaintext
...
@@ -798,10 +800,33 @@ in any other way.
...
@@ -798,10 +800,33 @@ in any other way.
Analogous to @code
{
twofish
_
encrypt
}
Analogous to @code
{
twofish
_
encrypt
}
@end deftypefun
@end deftypefun
@node C
BC
@node C
ipher Block Chaining, Miscellaneous functions, Cipher functions, Reference
@comment node-name, next, previous, up
@comment node-name, next, previous, up
@section Cipher Block Chaining
@section Cipher Block Chaining
When using CBC mode, cleartext blocks are not encrypted independently of
each other, like in Electronic Cookbook mode. Instead, when encrypting a
block in CBC mode, the previous ciphertext block is XOR:ed with the
cleartext before it is fed to the block cipher. When encrypting the
first block, a random block called an @dfn
{
IV
}
, or Initialization
Vector, is used as the ``previous ciphertext block''. The IV should be
chosen randomly, but it need not be kept secret, and can even be
transmitted in the clear together with the encrypted data.
In symbols, if @code
{
E
_
k
}
is the encryption function of a blockcipher,
and @code
{
IV
}
is the initialization vector, then @code
{
n
}
cleartext blocks
@code
{
M
_
1
}
,@dots
{}
@code
{
M
_
n
}
are transformed into @code
{
n
}
ciphertext blocks
@code
{
C
_
1
}
,@dots
{}
@code
{
C
_
n
}
as follows:
@example
C
_
1 = E
_
k(IV XOR M
_
1)
C
_
2 = E
_
k(C
_
1 XOR M
_
2)
@dots
{}
C
_
n = E
_
k(C
_
(n-1) XOR M
_
n)
@end example
Nettle includes a few utility functions for applying a block cipher in
Nettle includes a few utility functions for applying a block cipher in
Cipher Block Chaining (CBC) mode. The functions uses @code
{
void *
}
to
Cipher Block Chaining (CBC) mode. The functions uses @code
{
void *
}
to
pass cipher contexts around.
pass cipher contexts around.
...
@@ -810,15 +835,18 @@ pass cipher contexts around.
...
@@ -810,15 +835,18 @@ pass cipher contexts around.
@deftypefunx
{
void
}
cbc
_
decrypt (void *@var
{
ctx
}
, void (*@var
{
f
}
)(), unsigned @var
{
block
_
size
}
, uint8
_
t *@var
{
iv
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
dst
}
, const uint8
_
t *@var
{
src
}
)
@deftypefunx
{
void
}
cbc
_
decrypt (void *@var
{
ctx
}
, void (*@var
{
f
}
)(), unsigned @var
{
block
_
size
}
, uint8
_
t *@var
{
iv
}
, unsigned @var
{
length
}
, uint8
_
t *@var
{
dst
}
, const uint8
_
t *@var
{
src
}
)
Applies the encryption or decryption function @var
{
f
}
in CBC mde. The
Applies the encryption or decryption function @var
{
f
}
in CBC mde. The
function f is really typed as @code
{
void f (void *@var
{
ctx
}
, unsigned
function @var
{
f
}
is really typed as
@var
{
length
}
, uint8
_
t @var
{
dst
}
, const uint8
_
t *@var
{
src
}
), and the
@code
{
cbc
_
encrypt
}
and @code
{
cbc
_
decrypt
}
functions pass their argument
@code
{
void f (void *@var
{
ctx
}
, unsigned @var
{
length
}
, uint8
_
t @var
{
dst
}
,
@var
{
ctx
}
on to @code
{
f
}
.
const uint8
_
t *@var
{
src
}
)
}
,
@noindent and the @code
{
cbc
_
encrypt
}
and @code
{
cbc
_
decrypt
}
functions pass their
argument @var
{
ctx
}
on to @var
{
f
}
.
@end deftypefun
There are also some macros to help use these functions correctly. The
There are also some macros to help use these functions correctly.
are best explained by example.
@deffn Macro CBC
_
CTX (@var
(
context
_
type
)
, @var
(
block
_
size
)
)
@deffn Macro CBC
_
CTX (@var
{
context
_
type
}
, @var
{
block
_
size
}
)
Expands into
Expands into
@example
@example
@
{
@
{
...
@@ -826,7 +854,10 @@ Expands into
...
@@ -826,7 +854,10 @@ Expands into
uint8
_
t iv[block
_
size];
uint8
_
t iv[block
_
size];
@
}
@
}
@end example
@end example
It can be used to define a CBC context stuct, either directly
@end deffn
It can be used to define a CBC context stuct, either directly,
@example
@example
struct CBC
_
CTX(struct aes
_
ctx, AES
_
BLOCK
_
SIZE) ctx;
struct CBC
_
CTX(struct aes
_
ctx, AES
_
BLOCK
_
SIZE) ctx;
@end example
@end example
...
@@ -837,19 +868,27 @@ or to give it a struct tag,
...
@@ -837,19 +868,27 @@ or to give it a struct tag,
struct aes
_
cbc
_
ctx CBC
_
CTX (struct aes
_
ctx, AES
_
BLOCK
_
SIZE);
struct aes
_
cbc
_
ctx CBC
_
CTX (struct aes
_
ctx, AES
_
BLOCK
_
SIZE);
@end example
@end example
@deffn Macro CBC
_
SET
_
KEY
(@var
{
ctx
}
, @var
{
iv
}
)
@deffn Macro CBC
_
SET
_
IV
(@var
{
ctx
}
, @var
{
iv
}
)
First argument is a pointer to a context struct as defined by @code
{
CBC
_
CTX
}
,
First argument is a pointer to a context struct as defined by @code
{
CBC
_
CTX
}
,
and the second is a pointer to an Initialization Vector (iv) that is
and the second is a pointer to an Initialization Vector (IV) that is
copied into the context.
copied into that context.
@end deffn
@deffn Macro CBC
_
ENCRYPT (@var
{
ctx
}
, @var
{
f
}
, @var
{
length
}
, @var
{
dst
}
, @var
{
src
}
)
@deffn Macro CBC
_
ENCRYPT (@var
{
ctx
}
, @var
{
f
}
, @var
{
length
}
, @var
{
dst
}
, @var
{
src
}
)
@deffnx Macro CBC
_
DECRYPT (@var
{
ctx
}
, @var
{
f
}
, @var
{
length
}
, @var
{
dst
}
, @var
{
src
}
)
@deffnx Macro CBC
_
DECRYPT (@var
{
ctx
}
, @var
{
f
}
, @var
{
length
}
, @var
{
dst
}
, @var
{
src
}
)
A simpler way to invoke @code
{
cbc
_
encrypt
}
and @code
{
cbc
_
decrypt
}
. First
A simpler way to invoke @code
{
cbc
_
encrypt
}
and @code
{
cbc
_
decrypt
}
. The first
argument is XXX Here
argument is a context struct as defined by @code
{
CBC
_
CTX
}
, the second
argument is an encryption or decryption function following Nettle's
conventions. The last three arguments define the source and destination
area for the operation.
@end deffn
These macros use some tricks to make the compiler display a warning if
the types of @var
{
f
}
and @var
{
ctx
}
don't match, e.g. if you try to use
an @code
{
struct aes
_
ctx
}
context with the @code
{
des
_
encrypt
}
function.
@node Miscellaneous functions, , Cipher
functions
, Reference
@node Miscellaneous functions, , Cipher
Block Chaining
, Reference
@comment node-name, next, previous, up
@comment node-name, next, previous, up
@section Miscellaneous functions
@section Miscellaneous functions
...
...
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