From df5be903dfc32e887317a677fa1e0c9eda3ebcaa Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Thu, 2 May 2019 15:10:08 +0200 Subject: crypto: Doc link fixes --- lib/crypto/doc/src/crypto.xml | 16 ++++----- lib/crypto/doc/src/new_api.xml | 81 +++++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 29 deletions(-) diff --git a/lib/crypto/doc/src/crypto.xml b/lib/crypto/doc/src/crypto.xml index 751cf9d1fc..d1d1252f29 100644 --- a/lib/crypto/doc/src/crypto.xml +++ b/lib/crypto/doc/src/crypto.xml @@ -678,7 +678,8 @@

For encryption, set the EncryptFlag to true. For decryption, set it to false.

-

See examples in the User's Guide. +

See + examples in the User's Guide.

@@ -696,7 +697,8 @@ or crypto_init/4.

-

See examples in the User's Guide. +

See + examples in the User's Guide.

@@ -712,8 +714,6 @@

For encryption, set the EncryptFlag to true. For decryption, set it to false.

-

See examples in the User's Guide. -

@@ -726,8 +726,6 @@ The State should be created with crypto_dyn_iv_init/3.

-

See examples in the User's Guide. -

@@ -744,11 +742,11 @@ Do a complete encrypt or decrypt of the full text

Part of the new API. - Do a complete encrypt or decrypt of the full text. + Do a complete encrypt or decrypt of the full text in the argument Data.

For encryption, set the EncryptFlag to true. For decryption, set it to false.

-

See examples in the User's Guide. +

See examples in the User's Guide.

@@ -768,7 +766,7 @@

For decryption, set the EncryptFlag to false and put the tag to be checked in the argument TagOrTagLength.

-

See examples in the User's Guide. +

See examples in the User's Guide.

diff --git a/lib/crypto/doc/src/new_api.xml b/lib/crypto/doc/src/new_api.xml index 58ace97554..bd2334ac9f 100644 --- a/lib/crypto/doc/src/new_api.xml +++ b/lib/crypto/doc/src/new_api.xml @@ -59,9 +59,9 @@ stream_init/3 stream_encrypt/2 stream_decrypt/2 - suppports/0 + supports/0 -

They are not deprecated for now, but may be in a future. +

They are not deprecated for now, but may be in a future release.

@@ -76,7 +76,8 @@ crypto_one_time_aead/7

In those functions the internal crypto state is first created and initialized - with the cipher type, the key and possibly other data. Then the data is encrypted or decrypted, + with the cipher type, the key and possibly other data. Then the single binary is encrypted + or decrypted, the crypto state is de-allocated and the result of the crypto operation is returned.

The crypto_one_time_aead functions are for the ciphers of mode ccm or @@ -114,29 +115,39 @@

Examples of crypto_init/4 and crypto_update/2 -

Encrypting two blocks:

+

The functions crypto_init/4 + and crypto_update/2 are intended + to be used for encrypting or decrypting a sequence of blocks. First one call of + crypto_init/4 initialises the crypto context. One or more calls crypto_update/2 + does the actual encryption or decryption for each block. +

+

This example shows first the encryption of two blocks and then decryptions of the cipher + text, but divided into three blocks just to show that it is possible to divide the plain text and + cipher text differently for some ciphers:

1> crypto:start(). ok 2> Key = <<1:128>>. - 2> IV = <<0:128>>. - 2> StateEnc = crypto:crypto_init(aes_128_ctr, Key, IV, true). % encrypt -> true + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>> + 3> IV = <<0:128>>. + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>> + 4> StateEnc = crypto:crypto_init(aes_128_ctr, Key, IV, true). % encrypt -> true #Ref<0.3768901617.1128660993.124047> - 3> crypto:crypto_update(StateEnc, <<"First bytes">>). + 5> crypto:crypto_update(StateEnc, <<"First bytes">>). <<67,44,216,166,25,130,203,5,66,6,162>> - 4> crypto:crypto_update(StateEnc, <<"Second bytes">>). + 6> crypto:crypto_update(StateEnc, <<"Second bytes">>). <<16,79,94,115,234,197,94,253,16,144,151,41>> - 5> - 5> StateDec = crypto:crypto_init(aes_128_ctr, Key, IV, false). % decrypt -> false + 7> + 7> StateDec = crypto:crypto_init(aes_128_ctr, Key, IV, false). % decrypt -> false #Ref<0.3768901617.1128660994.124255> - 6> crypto:crypto_update(StateDec, <<67,44,216,166,25,130,203>>). + 8> crypto:crypto_update(StateDec, <<67,44,216,166,25,130,203>>). <<"First b">> - 7> crypto:crypto_update(StateDec, <<5,66,6,162,16,79,94,115,234,197, - 94,253,16,144,151>>). + 9> crypto:crypto_update(StateDec, <<5,66,6,162,16,79,94,115,234,197, + 94,253,16,144,151>>). <<"ytesSecond byte">> - 8> crypto:crypto_update(StateDec, <<41>>). + 10> crypto:crypto_update(StateDec, <<41>>). <<"s">> - 9> + 11>

Note that the internal data that the StateEnc and StateDec references are destructivly updated by the calls to crypto_update/2. @@ -163,21 +174,51 @@ Example of crypto_one_time/5

The same example as in the previous section, - but now with one call to crypto_one_time/5: + but now with one call to crypto_one_time/5:

- 2> Key = <<1:128>>. + 1> Key = <<1:128>>. + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>> 2> IV = <<0:128>>. - 2> Txt = [<<"First bytes">>,<<"Second bytes">>], - 2> crypto:crypto_one_time(aes_128_ctr, Key, IV, Txt, true). + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>> + 3> Txt = [<<"First bytes">>,<<"Second bytes">>]. + [<<"First bytes">>,<<"Second bytes">>] + 4> crypto:crypto_one_time(aes_128_ctr, Key, IV, Txt, true). <<67,44,216,166,25,130,203,5,66,6,162,16,79,94,115,234, 197,94,253,16,144,151,41>> - 3> + 5>

The [<<"First bytes">>,<<"Second bytes">>] could of course have been one single binary: <<"First bytesSecond bytes">>.

+ +
+ Example of crypto_one_time_aead/6 +

The same example as in the + previous section, + but now with one call to crypto_one_time_aead/6: +

+ + 1> Key = <<1:128>>. + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>> + 2> IV = <<0:128>>. + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>> + 3> Txt = [<<"First bytes">>,<<"Second bytes">>]. + [<<"First bytes">>,<<"Second bytes">>] + 4> AAD = <<"Some bytes">>. + <<"Some bytes">> + 5> crypto:crypto_one_time_aead(aes_128_gcm, Key, IV, Txt, AAD, true). + {<<240,130,38,96,130,241,189,52,3,190,179,213,132,1,72, + 192,103,176,90,104,15,71,158>>, + <<131,47,45,91,142,85,9,244,21,141,214,71,31,135,2,155>>} + 9> + +

The [<<"First bytes">>,<<"Second bytes">>] could of course have been one + single binary: <<"First bytesSecond bytes">>. +

+
+
-- cgit v1.2.3