Skip to Content
📢 Breaking change: Applications using LedgerJS for transport implementation should migrate to the Device Management Kit (DMK). Learn more.
DocumentationDevice AppReferencesCryptography API

Cryptography library and syscalls reference

The cryptography library provides a C/C++ API for cryptographic operations in Ledger device applications. This Doxygen-generated reference covers the available cryptographic functions, data structures, error codes, and system calls.

Overview

This API reference covers:

  • Cryptographic algorithms: Implementations of industry-standard cryptographic primitives
  • Data structures: Cryptographic data types and structures
  • Function APIs: Function signatures, parameters, and return values
  • Error handling: Error codes and exception handling
  • System integration: Low-level system calls and hardware integration

Included APIs

The API reference covers the following areas:

Hash functions

  • BLAKE2b: Cryptographic hash function with configurable output size
  • RIPEMD160: 160-bit cryptographic hash function
  • SHA family: SHA224, SHA256, SHA384, and SHA512 implementations
  • SHA-3: SHA3-256, SHA3-384, SHA3-512, Keccak, SHAKE128, SHAKE256
  • Groestl: Hash function with various output sizes

Symmetric encryption

  • AES (Advanced Encryption Standard): AES implementation with hardware acceleration support
  • DES (Data Encryption Standard): Legacy DES encryption for compatibility

Asymmetric cryptography

  • RSA: RSA encryption, decryption, and digital signatures with key sizes from 1024 to 4096 bits
  • Elliptic curve cryptography (ECC):
    • ECDH (Elliptic Curve Diffie-Hellman) key exchange
    • ECDSA (Elliptic Curve Digital Signature Algorithm)
    • EdDSA (Edwards-curve Digital Signature Algorithm)
    • ECSchnorr signatures
  • Curve support: Weierstrass, Montgomery, and Twisted Edwards curves

Key management

  • AES keys: 128-, 192-, and 256-bit key handling
  • RSA keys: Private and public key structures for various bit lengths
  • ECC keys: Elliptic curve key pairs with different curve parameters
  • Key generation: Secure key generation and validation functions

Mathematical operations

  • Big number arithmetic: Big number library (cx_bn_* functions)
    • Addition, multiplication, modular operations
    • Prime number testing and generation
    • Bit manipulation and comparison operations
  • Modular arithmetic: Specialized modular math functions (cx_math_*)

Random number generation

  • True random number generator (TRNG): Hardware-based entropy source
  • Deterministic random bit generator: RFC 6979-compliant random number generation
  • Cryptographically secure RNG: Random number generation functions

Error handling

  • Error codes: Error definitions in cx_errors.h
  • Exception handling: Error propagation and handling mechanisms

Utility functions

  • CRC operations: Hardware-accelerated CRC16 and CRC32 implementations
  • Memory management: Secure memory handling and cleanup functions
  • Chaining modes: Support for CBC, CFB, CTR, ECB, and OFB block cipher modes

Data structures

The API includes more than 30 specialized data structures for cryptographic operations:

  • Hash state structures (cx_sha256_s, cx_sha3_s, blake2b_state__, etc.)
  • Key structures for all supported algorithms (cx_aes_key_s, cx_rsa_*_key_s, cx_ecfp_*_key_s)
  • Curve domain parameters (cx_curve_domain_s, cx_curve_weierstrass_s, etc.)
  • Big number contexts (cx_bn_mont_ctx_t)
  • HMAC contexts for various hash functions

Download the full documentation

The complete cryptography library and syscalls reference is available as an 805KB PDF. This Doxygen-generated reference includes API documentation for all functions, complete data structure definitions, and implementation details.

📄 Download complete Cryptography API reference (PDF, 805KB) 

Generated: December 18, 2023 | Format: Doxygen PDF Documentation

Implementation examples

The Cryptography API Examples page shows how to implement cryptographic operations with the API. It provides C code for digital signature algorithms, including ECDSA with Secp256k1, Ed25519, and Ed448 curves, as well as Schnorr signatures. It also covers AES and DES encryption and decryption with chaining modes such as CBC. The examples include key generation, message signing and verification, encryption and decryption, initialization, error handling, and explanations of the relevant cryptographic concepts.

Last updated on
Ledger
Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Stax, Ledger Flex, Ledger Nano, Ledger Nano S, Ledger OS, Ledger Wallet, [LEDGER] (logo), [L] (logo) are trademarks owned by Ledger SAS.