2
0

kem_util.c 993 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright 2022 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 <string.h> /* for memcpy() */
  10. #include <openssl/core_names.h>
  11. #include <openssl/crypto.h>
  12. #include "eckem.h"
  13. typedef struct {
  14. unsigned int id;
  15. const char *mode;
  16. } KEM_MODE;
  17. static const KEM_MODE eckem_modename_id_map[] = {
  18. { KEM_MODE_DHKEM, OSSL_KEM_PARAM_OPERATION_DHKEM },
  19. { 0, NULL }
  20. };
  21. int ossl_eckem_modename2id(const char *name)
  22. {
  23. size_t i;
  24. if (name == NULL)
  25. return KEM_MODE_UNDEFINED;
  26. for (i = 0; eckem_modename_id_map[i].mode != NULL; ++i) {
  27. if (OPENSSL_strcasecmp(name, eckem_modename_id_map[i].mode) == 0)
  28. return eckem_modename_id_map[i].id;
  29. }
  30. return KEM_MODE_UNDEFINED;
  31. }