/usr/lib/swipl/library/ext/ssl/crypto.pl
All Application Manual Name SummaryHelp

  • ext
    • ssl
      • ssl.pl -- Secure Socket Layer (SSL) library
      • crypto.pl -- Cryptography and authentication library
        • crypto_n_random_bytes/2
        • crypto_data_hash/3
        • crypto_file_hash/3
        • crypto_context_new/2
        • crypto_data_context/3
        • crypto_context_hash/2
        • crypto_open_hash_stream/3
        • crypto_stream_hash/2
        • crypto_password_hash/2
        • crypto_password_hash/3
        • crypto_data_hkdf/4
        • ecdsa_sign/4
        • ecdsa_verify/4
        • ed25519_new_keypair/1
        • ed25519_seed_keypair/2
        • ed25519_keypair_public_key/2
        • ed25519_sign/4
        • ed25519_verify/4
        • curve25519_generator/1
        • curve25519_scalar_mult/3
        • hex_bytes/2
        • rsa_private_decrypt/4
        • rsa_private_encrypt/4
        • rsa_public_decrypt/4
        • rsa_public_encrypt/4
        • rsa_sign/4
        • rsa_verify/4
        • crypto_data_decrypt/6
        • crypto_data_encrypt/6
        • crypto_modular_inverse/3
        • crypto_generate_prime/3
        • crypto_is_prime/2
        • crypto_name_curve/2
        • crypto_curve_order/2
        • crypto_curve_generator/2
        • crypto_curve_scalar_mult/4
      • xmlenc.pl
      • xmldsig.pl
 curve25519_scalar_mult(+Scalar, +Point, -Result) is semidet
Result is the point Scalar*Point on Curve25519, as mandated by X25519 (RFC 7748). Scalar is an integer between 0 and 2^256-1, or 32 bytes. Fails if Point has small order, i.e., if the result would be the point at infinity.

Alice and Bob can use this to establish a shared secret, where Generator is obtained with curve25519_generator/1:

  1. Alice creates a random integer a and sends As = a*Generator to Bob.
  2. Bob creates a random integer b and sends Bs = b*Generator to Alice.
  3. Alice computes Rs = a*Bs.
  4. Bob computes Rs = b*As.
  5. Alice and Bob use crypto_data_hkdf/4 on Rs with suitable (same) parameters to obtain keys and initialization vectors for symmetric encryption.

If a and b are kept secret, this method is considered very secure.