The module cryptography
The cryptography of the system as one module of code: each export is a primitive of Odin's core:crypto that the system took (src/library/modus/cryptography, Cryptography), in the forms of the system.
The code of each export but argon2id is in the private part cryptography_primitives, under the same name and with the same signature: the QUIC peer of the tool and the host tests of QUIC call that code on the host, where no module is loaded. The export reads each argument once and passes it on.
- The caller supplies the memory: each Text is bytes of the caller, each result is a buffer of the caller, so the module allocates nothing.
- Each byte of the caller is read once, and each input that the code of the origin reads more than once is first copied into memory of the module, with a limit.
- The result buffer must be private memory of the caller. The module says which arguments must be private.
- A failure is an error record and a negative count, never a boolean that a caller can forget.
- The copies of secrets that the module makes are erased, and so is the stack below each export after the work (
erase_stack_below_the_caller).
A process says which cryptography it runs by the hash of this module: the hash names exactly the code that runs. The names of the algorithms stay as their standards write them.
cryptography module with no entry
- Hash
b8cf5a11cd44879b8206a0fe93d67306358fd91ed566e304651d00a76e7e1568- Size
309369 bytes- Exports
15- Imports
0- Imported by
5- License
- MIT
The cryptography of the system as one module of code: each export is a primitive of Odin's core:crypto that the system took (src/library/modus/cryptography), in the forms of the system
| Fact | Value |
|---|---|
| Kind | Modules with no entry |
| Source | src/modules/libraries/cryptography |
| Boot image | yes: in the boot image, 309369 bytes in this build |
| Build settings | none: the defaults of the source |
| Imports | none |
| Imported by |
Neighbours
What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.
Exports
| Export | What it does |
|---|---|
seal_with_chacha20_poly1305(key: Text, nonce: Text, additional: Text, text: Text) -> Text | encrypts a text and appends its tag of 16 bytes (RFC 8439) |
open_with_chacha20_poly1305(key: Text, nonce: Text, additional: Text, sealed: Text) -> Text | checks the tag of a sealed text and decrypts it (RFC 8439) |
seal_with_aes_128_gcm(key: Text, nonce: Text, additional: Text, text: Text) -> Text | encrypts a text and appends its tag of 16 bytes (NIST SP 800-38D) |
open_with_aes_128_gcm(key: Text, nonce: Text, additional: Text, sealed: Text) -> Text | checks the tag of a sealed text and decrypts it |
sha256(text: Text) -> Text | gives the SHA-256 hash of a text: 32 bytes (FIPS 180-4) |
hmac_sha256(key: Text, text: Text) -> Text | gives the HMAC of a text with a key, with SHA-256: 32 bytes (RFC 2104) |
hkdf_sha256_extract(salt: Text, input: Text) -> Text | gives the pseudorandom key of HKDF from a salt and input keying material, with SHA-256: 32 bytes (RFC 5869, section 2.2) |
hkdf_sha256_expand(key: Text, info: Text, length: Integer) -> Text | gives length bytes of output keying material from a pseudorandom key and an info text, with SHA-256 (RFC 5869, section 2.3) |
header_protection_mask_with_aes_128(key: Text, sample: Text) -> Text | gives the 5 bytes of the QUIC header protection mask of a sample of 16 bytes with a key of 16 bytes: AES-128 of the sample (RFC 9001, section 5.4.3) |
header_protection_mask_with_chacha20(key: Text, sample: Text) -> Text | gives the 5 bytes of the QUIC header protection mask of a sample of 16 bytes with a key of 32 bytes: the ChaCha20 keystream at the counter and the nonce that the sample gives (RFC 9001, section 5.4.4) |
x25519(scalar: Text, point: Text) -> Text | gives the shared secret of a scalar of 32 bytes and a point of 32 bytes (RFC 7748); with the point 9 it is the public key of the scalar |
ed25519_public_key(secret: Text) -> Text | gives the public key of a private key of 32 bytes (RFC 8032, section 5.1.5) |
ed25519_sign(secret: Text, message: Text) -> Text | gives the signature of a message of 4096 bytes at most, 64 bytes, with a private key of 32 bytes (RFC 8032, section 5.1.6) |
ed25519_verify(public: Text, message: Text, signature: Text) -> Integer | checks the signature of a message of 4096 bytes at most with a public key of 32 bytes (RFC 8032, section 5.1.7) |
argon2id(password: Text, salt: Text, cost: Argon2id_Cost, work: Bytes(Change)) -> Text | derives a key from a password and a salt with Argon2id (RFC 9106), at the cost of the record: the KiB of the blocks, the passes, the lanes and the bytes of the key |
seal_with_chacha20_poly1305
seal_with_chacha20_poly1305(key: , nonce: , additional: , text: ) ->
seal_with_chacha20_poly1305 encrypts a text and appends its tag of 16 bytes (RFC 8439).
key: 32 bytes.nonce: 12 bytes. A nonce must never come two times with one key: that is the duty of the caller.additional: the additional data, which the tag covers and which is not encrypted: 2048 bytes at most.text: the text to encrypt.result: room for the bytes of the text and 16 more, in private memory of the caller.
Result: the count of bytes (the size that the result needs, when it is too small), or a negative number with an error record:
Empty,Too_SmallorToo_Long: a key, a nonce or a text of another size;Bad_Value: a result that overlaps an argument.
key:nonce:additional:text:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:52
open_with_chacha20_poly1305
open_with_chacha20_poly1305(key: , nonce: , additional: , sealed: ) ->
open_with_chacha20_poly1305 checks the tag of a sealed text and decrypts it (RFC 8439).
The key, the nonce and the additional data are those of the seal (seal). The result must be private memory of the caller, with room for the text: the sealed text minus 16 bytes.
Result: the count of bytes, or a negative number with an error record:
Not_Authentic: the tag does not verify; the result keeps no byte of the text;Too_Small: a sealed text under 16 bytes, or a result with no room;Bad_Value: a result that overlaps an argument.
key:nonce:additional:sealed:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:67
seal_with_aes_128_gcm
seal_with_aes_128_gcm(key: , nonce: , additional: , text: ) ->
seal_with_aes_128_gcm encrypts a text and appends its tag of 16 bytes (NIST SP 800-38D).
The key has 16 bytes, the nonce 12. A nonce must never come two times with one key: with AES-GCM a repeated nonce gives away the key of the tag, and with it forgeries. The other rules of the arguments and of the result are those of the seal with ChaCha20-Poly1305.
key:nonce:additional:text:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:77
open_with_aes_128_gcm
open_with_aes_128_gcm(key: , nonce: , additional: , sealed: ) ->
open_with_aes_128_gcm checks the tag of a sealed text and decrypts it.
The rules of the arguments, of the result and of the errors are those of the open with ChaCha20-Poly1305.
key:nonce:additional:sealed:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:86
sha256
sha256(text: ) ->
sha256 gives the SHA-256 hash of a text: 32 bytes (FIPS 180-4).
- text: the bytes to hash, of any length.
- result: a buffer of 32 bytes at least.
Result: 32. A buffer under 32 bytes receives nothing, and the result 32 says how much room the hash needs. It has no error record: each text has a hash. The stack below the export is erased after the work, because a text can be a secret (a transcript, a key).
Example, after load("cryptography"): sha256("abc") gives the 32 bytes that start with ba 78 16 bf.
hmac_sha256
hmac_sha256(key: , text: ) ->
hmac_sha256 gives the HMAC of a text with a key, with SHA-256: 32 bytes (RFC 2104).
- key: the key, of any length; a key longer than 64 bytes is hashed first, as the standard says.
- text: the bytes to authenticate.
- result: a buffer of 32 bytes at least.
Result: 32. A buffer under 32 bytes receives nothing. The tag is computed in memory of the module, then copied: the buffer of the caller never holds a part of the work. The copy of the tag is erased.
hkdf_sha256_extract
hkdf_sha256_extract(salt: , input: ) ->
hkdf_sha256_extract gives the pseudorandom key of HKDF from a salt and input keying material, with SHA-256: 32 bytes (RFC 5869, section 2.2).
hkdf_sha256_expand
hkdf_sha256_expand(key: , info: , length: ) ->
hkdf_sha256_expand gives length bytes of output keying material from a pseudorandom key and an info text, with SHA-256 (RFC 5869, section 2.3).
- The key: 32 bytes at least, as the extract gives it.
- The info: 1024 bytes at most.
- The length: 1 to 8160 bytes, 255 times the size of a hash.
Result: the count of bytes, or a negative number with an error record.
key:info:length:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:132
header_protection_mask_with_aes_128
header_protection_mask_with_aes_128(key: , sample: ) ->
header_protection_mask_with_aes_128 gives the 5 bytes of the QUIC header protection mask of a sample of 16 bytes with a key of 16 bytes: AES-128 of the sample (RFC 9001, section 5.4.3). The result is 5, or a negative number with an error record for a key or a sample of another size.
- key: the header protection key of 16 bytes (argument 1).
- sample: the 16 bytes of the protected packet that the standard names (argument 2).
- result: a buffer of 5 bytes at least; a shorter buffer receives nothing, and the result is 5.
The errors: Empty, Too_Small or Too_Long for a key or a sample of another size, with the number of the argument. The copy of the key is erased. The QUIC library of the system calls it for each packet of a suite with AES.
key:sample:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:146
header_protection_mask_with_chacha20
header_protection_mask_with_chacha20(key: , sample: ) ->
header_protection_mask_with_chacha20 gives the 5 bytes of the QUIC header protection mask of a sample of 16 bytes with a key of 32 bytes: the ChaCha20 keystream at the counter and the nonce that the sample gives (RFC 9001, section 5.4.4). The result is 5, or a negative number with an error record for a key or a sample of another size.
- key: the header protection key of 32 bytes (argument 1).
- sample: 16 bytes of the protected packet: the first 4 are the counter, the other 12 the nonce (argument 2).
- result: a buffer of 5 bytes at least; a shorter buffer receives nothing, and the result is 5.
The errors are those of the mask with AES-128.
key:sample:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:158
x25519
x25519(scalar: , point: ) ->
x25519 gives the shared secret of a scalar of 32 bytes and a point of 32 bytes (RFC 7748); with the point 9 it is the public key of the scalar.
A point of small order, whose shared secret is 32 zero bytes, is refused with Bad_Value (RFC 7748, section 6.1): such a secret is known to anyone.
scalar:point:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:167
ed25519_public_key
ed25519_public_key(secret: ) ->
ed25519_public_key gives the public key of a private key of 32 bytes (RFC 8032, section 5.1.5).
secret:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:173
ed25519_sign
ed25519_sign(secret: , message: ) ->
ed25519_sign gives the signature of a message of 4096 bytes at most, 64 bytes, with a private key of 32 bytes (RFC 8032, section 5.1.6).
secret:message:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:179
ed25519_verify
ed25519_verify(public: , message: , signature: ) ->
ed25519_verify checks the signature of a message of 4096 bytes at most with a public key of 32 bytes (RFC 8032, section 5.1.7).
The check is strict: a signature with a non-canonical S or R, or a public key of small order, is refused.
Result: 0, or a negative number with an error record:
Not_Authentic: the signature does not verify;Bad_Value: a public key that is not a point.
public:message:signature:
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:192
argon2id
argon2id(password: , salt: , cost: , work: (Change)) ->
argon2id derives a key from a password and a salt with Argon2id (RFC 9106), at the cost of the record: the KiB of the blocks, the passes, the lanes and the bytes of the key.
- 1. The password: 1024 bytes at most.
- 2. The salt: 8 to 64 bytes.
- 3. The cost: an
Argon2id_Cost. - 4. The work: the blocks, which the caller supplies:
memory_kibibytes * 1024bytes of its own memory, aligned on 8 bytes, which the module erases at the end.
Result: the count of the bytes of the key, or a negative number with an error record:
Too_Long: the password (argument 1);Too_SmallorToo_Long: the salt (argument 2);Bad_Value: the cost (argument 3);Too_Small: the work memory (argument 4).
password:salt:cost:work: (Change)
- When it fails
- a negative result, and the error record
src/modules/libraries/cryptography/cryptography.odin:292
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
Text wire form
A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.
Error_Record record of a module
A record of the module cryptography: 56 bytes, aligned on 8 bytes, 0 bytes of padding.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
Integer wire form
A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.
Argon2id_Cost record of a module
A record of the module cryptography: 32 bytes, aligned on 8 bytes, 0 bytes of padding.
memory_kibibytesi6408 bytespassesi6488 byteslanesi64168 bytestag_bytesi64248 bytes
Bytes wire form
A wire form of the module contract: one word of a call. Bytes with no description.
