quic_types.c 803 B

1234567891011121314151617181920212223242526272829
  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. #include "internal/quic_types.h"
  10. #include <openssl/rand.h>
  11. #include <openssl/err.h>
  12. int ossl_quic_gen_rand_conn_id(OSSL_LIB_CTX *libctx, size_t len,
  13. QUIC_CONN_ID *cid)
  14. {
  15. if (len > QUIC_MAX_CONN_ID_LEN)
  16. return 0;
  17. cid->id_len = (unsigned char)len;
  18. if (RAND_bytes_ex(libctx, cid->id, len, len * 8) != 1) {
  19. ERR_raise(ERR_LIB_SSL, ERR_R_RAND_LIB);
  20. cid->id_len = 0;
  21. return 0;
  22. }
  23. return 1;
  24. }