| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 1 | ## RNG removal |
| 2 | |
| 3 | ### Public functions no longer take a RNG callback |
| 4 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 5 | Functions that need randomness no longer take an RNG callback in the form of `f_rng, p_rng` arguments. Instead, they use the PSA Crypto random generator (accessible as `psa_generate_random()`). All software using the X.509 or SSL modules must call `psa_crypto_init()` before calling any of the functions listed here. |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 6 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 7 | ### Changes in X.509 |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 8 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 9 | The following function prototypes have been changed in `mbedtls/x509_crt.h`: |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 10 | |
| 11 | ```c |
| 12 | int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, |
| 13 | int (*f_rng)(void *, unsigned char *, size_t), |
| 14 | void *p_rng); |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 15 | |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 16 | int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, |
| 17 | int (*f_rng)(void *, unsigned char *, size_t), |
| 18 | void *p_rng); |
| 19 | ``` |
| 20 | |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 21 | to |
| 22 | |
| 23 | ```c |
| 24 | int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size); |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 25 | |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 26 | int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size); |
| 27 | ``` |
| 28 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 29 | The following function prototypes have been changed in `mbedtls/x509_csr.h`: |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 30 | ```c |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 31 | int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 32 | int (*f_rng)(void *, unsigned char *, size_t), |
| 33 | void *p_rng); |
| 34 | |
| 35 | int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 36 | int (*f_rng)(void *, unsigned char *, size_t), |
| 37 | void *p_rng); |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 38 | ``` |
| 39 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 40 | to |
| 41 | |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 42 | ```c |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 43 | int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size); |
| 44 | |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 45 | int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size); |
| 46 | ``` |
| 47 | |
| 48 | ### Changes in SSL |
| 49 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 50 | The following function prototypes have been changed in `mbedtls/ssl.h`: |
| Gilles Peskine | cd5abfe | 2025-06-25 16:43:49 +0200 | [diff] [blame] | 51 | |
| 52 | ```c |
| 53 | int mbedtls_ssl_ticket_setup(mbedtls_ssl_ticket_context *ctx, |
| 54 | int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, |
| 55 | psa_algorithm_t alg, psa_key_type_t key_type, psa_key_bits_t key_bits, uint32_t lifetime); |
| 56 | ``` |
| 57 | |
| 58 | ```c |
| 59 | int mbedtls_ssl_cookie_setup(mbedtls_ssl_cookie_ctx *ctx, |
| 60 | int (*f_rng)(void *, unsigned char *, size_t), |
| 61 | void *p_rng); |
| 62 | ``` |
| 63 | |
| 64 | to |
| 65 | |
| 66 | ```c |
| 67 | int mbedtls_ssl_ticket_setup(mbedtls_ssl_ticket_context *ctx, |
| 68 | psa_algorithm_t alg, psa_key_type_t key_type, psa_key_bits_t key_bits, uint32_t lifetime); |
| 69 | ``` |
| 70 | |
| 71 | ```c |
| 72 | int mbedtls_ssl_cookie_setup(mbedtls_ssl_cookie_ctx *ctx); |
| 73 | ``` |
| 74 | |
| 75 | The following structs have also been changed in SSL |
| 76 | |
| 77 | ```c |
| 78 | typedef struct mbedtls_ssl_ticket_context { |
| 79 | mbedtls_ssl_ticket_key MBEDTLS_PRIVATE(keys)[2]; /*!< ticket protection keys */ |
| 80 | unsigned char MBEDTLS_PRIVATE(active); /*!< index of the currently active key */ |
| 81 | |
| 82 | uint32_t MBEDTLS_PRIVATE(ticket_lifetime); /*!< lifetime of tickets in seconds */ |
| 83 | |
| 84 | /** Callback for getting (pseudo-)random numbers */ |
| 85 | int(*MBEDTLS_PRIVATE(f_rng))(void *, unsigned char *, size_t); |
| 86 | void *MBEDTLS_PRIVATE(p_rng); /*!< context for the RNG function */ |
| 87 | |
| 88 | #if defined(MBEDTLS_THREADING_C) |
| 89 | mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); |
| 90 | #endif |
| 91 | } |
| 92 | mbedtls_ssl_ticket_context; |
| 93 | ``` |
| 94 | |
| 95 | |
| 96 | to |
| 97 | |
| 98 | ```c |
| 99 | typedef struct mbedtls_ssl_ticket_context { |
| 100 | mbedtls_ssl_ticket_key MBEDTLS_PRIVATE(keys)[2]; /*!< ticket protection keys */ |
| 101 | unsigned char MBEDTLS_PRIVATE(active); /*!< index of the currently active key */ |
| 102 | |
| 103 | uint32_t MBEDTLS_PRIVATE(ticket_lifetime); /*!< lifetime of tickets in seconds */ |
| 104 | |
| 105 | #if defined(MBEDTLS_THREADING_C) |
| 106 | mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); |
| 107 | #endif |
| 108 | } |
| 109 | mbedtls_ssl_ticket_context; |
| 110 | ``` |
| 111 | |
| 112 | ### Removal of `mbedtls_ssl_conf_rng` |
| 113 | |
| Gilles Peskine | 617ee75 | 2025-06-25 16:52:01 +0200 | [diff] [blame] | 114 | `mbedtls_ssl_conf_rng()` has been removed from the library. Its sole purpose was to configure the RNG used for TLS, but now the PSA Crypto random generator is used throughout the library. |