3 library(crypto): Cryptography and authentication library
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog SSL Interface
        • library(crypto): Cryptography and authentication library
          • Introduction
          • Design principle: Secure default algorithms
          • Representing binary data
          • Cryptographically secure random numbers
          • Hashes
          • Digital signatures
          • Asymmetric encryption and decryption
          • Symmetric encryption and decryption
          • Number theory
            • crypto_modular_inverse/3
            • crypto_generate_prime/3
            • crypto_is_prime/2
          • Elliptic curves
          • Example: Establishing a shared secret

3.9 Number theory

This library provides operations from number theory that frequently arise in cryptographic applications, complementing the existing built-ins and GMP bindings:

[det]crypto_modular_inverse(+X, +M, -Y)
Compute the modular multiplicative inverse of the integer X. Y is unified with an integer such that X*Y is congruent to 1 modulo M.
[det]crypto_generate_prime(+N, -P, +Options)
Generate a prime P with at least N bits. Options is a list of options. Currently, the only supported option is:
safe(Boolean)
If Boolean is true (default is false), then a safe prime is generated. This means that P is of the form 2*Q + 1 where Q is also prime.
[semidet]crypto_is_prime(+P, +Options)
True iff P passes a probabilistic primality test. Options is a list of options. Currently, the only supported option is:
iterations(N)
N is the number of iterations that are performed. If this option is not specified, a number of iterations is used such that the probability of a false positive is at most 2^(-80).