NetMD.Crypto (NetMD v0.1.0)

Copy Markdown View Source

DES primitives for the NetMD secure session, matching the CryptoJS usage in netmd-js. All inputs must be multiples of the 8-byte DES block size; the reference relies on the same alignment.

Summary

Functions

Two-key triple-DES CBC encryption (the 16-byte key expands to K1 K2 K1).

Single-DES CBC decryption.

Single-DES CBC encryption.

Single-DES ECB decryption.

Single-DES ECB encryption.

Decrypt data from an encrypted factory memory transfer (block-aligned).

Encrypt data for an encrypted factory memory transfer.

The retail MAC used to derive the secure session key.

Functions

des3_cbc_encrypt(key, iv, data)

@spec des3_cbc_encrypt(key :: <<_::128>>, iv :: <<_::64>>, binary()) :: binary()

Two-key triple-DES CBC encryption (the 16-byte key expands to K1 K2 K1).

des_cbc_decrypt(key, iv, data)

@spec des_cbc_decrypt(key :: <<_::64>>, iv :: <<_::64>>, binary()) :: binary()

Single-DES CBC decryption.

des_cbc_encrypt(key, iv, data)

@spec des_cbc_encrypt(key :: <<_::64>>, iv :: <<_::64>>, binary()) :: binary()

Single-DES CBC encryption.

des_ecb_decrypt(key, data)

@spec des_ecb_decrypt(key :: <<_::64>>, binary()) :: binary()

Single-DES ECB decryption.

des_ecb_encrypt(key, data)

@spec des_ecb_encrypt(key :: <<_::64>>, binary()) :: binary()

Single-DES ECB encryption.

factory_transfer_decrypt(data)

@spec factory_transfer_decrypt(binary()) :: binary()

Decrypt data from an encrypted factory memory transfer (block-aligned).

factory_transfer_encrypt(data)

@spec factory_transfer_encrypt(binary()) :: binary()

Encrypt data for an encrypted factory memory transfer.

Matches the reference: PKCS7-pad to the DES block size, ECB-encrypt with the fixed factory key, then drop the trailing padding block. For block-aligned input (what the callers produce) this is plain ECB.

retailmac(key, value, iv \\ "\0\0\0\0\0\0\0\0")

@spec retailmac(key :: <<_::128>>, value :: binary(), iv :: <<_::64>>) :: <<_::64>>

The retail MAC used to derive the secure session key.

DES-CBC over all but the last 8 bytes of value with the first half of key produces an intermediate IV; triple-DES-CBC over the final 8 bytes with the full key produces the MAC (first 8 bytes).