params.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #ifndef HEADER_PARAMS_H
  11. # define HEADER_PARAMS_H
  12. # include <openssl/core.h>
  13. # include <openssl/bn.h>
  14. # ifdef __cplusplus
  15. extern "C" {
  16. # endif
  17. # define OSSL_PARAM_END \
  18. { NULL, 0, NULL, 0, 0 }
  19. # define OSSL_PARAM_DEFN(key, type, addr, sz) \
  20. { (key), (type), (addr), (sz), 0 }
  21. /* Basic parameter types without return sizes */
  22. # define OSSL_PARAM_int(key, addr) \
  23. OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int))
  24. # define OSSL_PARAM_uint(key, addr) \
  25. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
  26. sizeof(unsigned int))
  27. # define OSSL_PARAM_long(key, addr) \
  28. OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(long int))
  29. # define OSSL_PARAM_ulong(key, addr) \
  30. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
  31. sizeof(unsigned long int))
  32. # define OSSL_PARAM_int32(key, addr) \
  33. OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int32_t))
  34. # define OSSL_PARAM_uint32(key, addr) \
  35. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
  36. sizeof(uint32_t))
  37. # define OSSL_PARAM_int64(key, addr) \
  38. OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int64_t))
  39. # define OSSL_PARAM_uint64(key, addr) \
  40. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
  41. sizeof(uint64_t))
  42. # define OSSL_PARAM_size_t(key, addr) \
  43. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), sizeof(size_t))
  44. # define OSSL_PARAM_double(key, addr) \
  45. OSSL_PARAM_DEFN((key), OSSL_PARAM_REAL, (addr), sizeof(double))
  46. # define OSSL_PARAM_BN(key, bn, sz) \
  47. OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (bn), (sz))
  48. # define OSSL_PARAM_utf8_string(key, addr, sz) \
  49. OSSL_PARAM_DEFN((key), OSSL_PARAM_UTF8_STRING, (addr), sz)
  50. # define OSSL_PARAM_octet_string(key, addr, sz) \
  51. OSSL_PARAM_DEFN((key), OSSL_PARAM_OCTET_STRING, (addr), sz)
  52. # define OSSL_PARAM_utf8_ptr(key, addr, sz) \
  53. OSSL_PARAM_DEFN((key), OSSL_PARAM_UTF8_PTR, &(addr), sz)
  54. # define OSSL_PARAM_octet_ptr(key, addr, sz) \
  55. OSSL_PARAM_DEFN((key), OSSL_PARAM_OCTET_PTR, &(addr), sz)
  56. /* Search an OSSL_PARAM array for a matching name */
  57. OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *p, const char *key);
  58. const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *p, const char *key);
  59. /* Basic parameter type run-time construction */
  60. OSSL_PARAM OSSL_PARAM_construct_int(const char *key, int *buf);
  61. OSSL_PARAM OSSL_PARAM_construct_uint(const char *key, unsigned int *buf);
  62. OSSL_PARAM OSSL_PARAM_construct_long(const char *key, long int *buf);
  63. OSSL_PARAM OSSL_PARAM_construct_ulong(const char *key, unsigned long int *buf);
  64. OSSL_PARAM OSSL_PARAM_construct_int32(const char *key, int32_t *buf);
  65. OSSL_PARAM OSSL_PARAM_construct_uint32(const char *key, uint32_t *buf);
  66. OSSL_PARAM OSSL_PARAM_construct_int64(const char *key, int64_t *buf);
  67. OSSL_PARAM OSSL_PARAM_construct_uint64(const char *key, uint64_t *buf);
  68. OSSL_PARAM OSSL_PARAM_construct_size_t(const char *key, size_t *buf);
  69. OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
  70. size_t bsize);
  71. OSSL_PARAM OSSL_PARAM_construct_double(const char *key, double *buf);
  72. OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
  73. size_t bsize);
  74. OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
  75. size_t bsize);
  76. OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
  77. size_t bsize);
  78. OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
  79. size_t bsize);
  80. OSSL_PARAM OSSL_PARAM_construct_end(void);
  81. int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val);
  82. int OSSL_PARAM_get_uint(const OSSL_PARAM *p, unsigned int *val);
  83. int OSSL_PARAM_get_long(const OSSL_PARAM *p, long int *val);
  84. int OSSL_PARAM_get_ulong(const OSSL_PARAM *p, unsigned long int *val);
  85. int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val);
  86. int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val);
  87. int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val);
  88. int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val);
  89. int OSSL_PARAM_get_size_t(const OSSL_PARAM *p, size_t *val);
  90. int OSSL_PARAM_set_int(OSSL_PARAM *p, int val);
  91. int OSSL_PARAM_set_uint(OSSL_PARAM *p, unsigned int val);
  92. int OSSL_PARAM_set_long(OSSL_PARAM *p, long int val);
  93. int OSSL_PARAM_set_ulong(OSSL_PARAM *p, unsigned long int val);
  94. int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val);
  95. int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val);
  96. int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val);
  97. int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val);
  98. int OSSL_PARAM_set_size_t(OSSL_PARAM *p, size_t val);
  99. int OSSL_PARAM_get_double(const OSSL_PARAM *p, double *val);
  100. int OSSL_PARAM_set_double(OSSL_PARAM *p, double val);
  101. int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val);
  102. int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val);
  103. int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val, size_t max_len);
  104. int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val);
  105. int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val, size_t max_len,
  106. size_t *used_len);
  107. int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val, size_t len);
  108. int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val);
  109. int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val);
  110. int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
  111. size_t *used_len);
  112. int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
  113. size_t used_len);
  114. # ifdef __cplusplus
  115. }
  116. # endif
  117. #endif