xref: /openssl/ssl/quic/quic_types.c (revision d59c3feb)
1 /*
2  * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include "internal/quic_types.h"
11 #include <openssl/rand.h>
12 #include <openssl/err.h>
13 
ossl_quic_gen_rand_conn_id(OSSL_LIB_CTX * libctx,size_t len,QUIC_CONN_ID * cid)14 int ossl_quic_gen_rand_conn_id(OSSL_LIB_CTX *libctx, size_t len,
15                                QUIC_CONN_ID *cid)
16 {
17     if (len > QUIC_MAX_CONN_ID_LEN)
18         return 0;
19 
20     cid->id_len = (unsigned char)len;
21 
22     if (RAND_bytes_ex(libctx, cid->id, len, len * 8) != 1) {
23         ERR_raise(ERR_LIB_SSL, ERR_R_RAND_LIB);
24         cid->id_len = 0;
25         return 0;
26     }
27 
28     return 1;
29 }
30