2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
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
12 #include <openssl/params.h>
13 #include "internal/thread_once.h"
14 #include "internal/numbers.h"
17 * Return the number of bits in the mantissa of a double. This is used to
18 * shift a larger integral value to determine if it will exactly fit into a
21 static unsigned int real_shift(void)
23 return sizeof(double) == 4 ? 24 : 53;
26 OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *p, const char *key)
28 if (p != NULL && key != NULL)
29 for (; p->key != NULL; p++)
30 if (strcmp(key, p->key) == 0)
35 const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *p, const char *key)
37 return OSSL_PARAM_locate((OSSL_PARAM *)p, key);
40 static OSSL_PARAM ossl_param_construct(const char *key, unsigned int data_type,
41 void *data, size_t data_size)
46 res.data_type = data_type;
48 res.data_size = data_size;
49 res.return_size = OSSL_PARAM_UNMODIFIED;
53 int OSSL_PARAM_modified(const OSSL_PARAM *p)
55 return p != NULL && p->return_size != OSSL_PARAM_UNMODIFIED;
58 void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p)
61 while (p->key != NULL)
62 p++->return_size = OSSL_PARAM_UNMODIFIED;
65 int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val)
67 switch (sizeof(int)) {
69 return OSSL_PARAM_get_int32(p, (int32_t *)val);
71 return OSSL_PARAM_get_int64(p, (int64_t *)val);
76 int OSSL_PARAM_set_int(OSSL_PARAM *p, int val)
78 switch (sizeof(int)) {
80 return OSSL_PARAM_set_int32(p, (int32_t)val);
82 return OSSL_PARAM_set_int64(p, (int64_t)val);
87 OSSL_PARAM OSSL_PARAM_construct_int(const char *key, int *buf)
89 return ossl_param_construct(key, OSSL_PARAM_INTEGER, buf, sizeof(int));
92 int OSSL_PARAM_get_uint(const OSSL_PARAM *p, unsigned int *val)
94 switch (sizeof(unsigned int)) {
95 case sizeof(uint32_t):
96 return OSSL_PARAM_get_uint32(p, (uint32_t *)val);
97 case sizeof(uint64_t):
98 return OSSL_PARAM_get_uint64(p, (uint64_t *)val);
103 int OSSL_PARAM_set_uint(OSSL_PARAM *p, unsigned int val)
105 switch (sizeof(unsigned int)) {
106 case sizeof(uint32_t):
107 return OSSL_PARAM_set_uint32(p, (uint32_t)val);
108 case sizeof(uint64_t):
109 return OSSL_PARAM_set_uint64(p, (uint64_t)val);
114 OSSL_PARAM OSSL_PARAM_construct_uint(const char *key, unsigned int *buf)
116 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER, buf,
117 sizeof(unsigned int));
120 int OSSL_PARAM_get_long(const OSSL_PARAM *p, long int *val)
122 switch (sizeof(long int)) {
123 case sizeof(int32_t):
124 return OSSL_PARAM_get_int32(p, (int32_t *)val);
125 case sizeof(int64_t):
126 return OSSL_PARAM_get_int64(p, (int64_t *)val);
131 int OSSL_PARAM_set_long(OSSL_PARAM *p, long int val)
133 switch (sizeof(long int)) {
134 case sizeof(int32_t):
135 return OSSL_PARAM_set_int32(p, (int32_t)val);
136 case sizeof(int64_t):
137 return OSSL_PARAM_set_int64(p, (int64_t)val);
142 OSSL_PARAM OSSL_PARAM_construct_long(const char *key, long int *buf)
144 return ossl_param_construct(key, OSSL_PARAM_INTEGER, buf, sizeof(long int));
147 int OSSL_PARAM_get_ulong(const OSSL_PARAM *p, unsigned long int *val)
149 switch (sizeof(unsigned long int)) {
150 case sizeof(uint32_t):
151 return OSSL_PARAM_get_uint32(p, (uint32_t *)val);
152 case sizeof(uint64_t):
153 return OSSL_PARAM_get_uint64(p, (uint64_t *)val);
158 int OSSL_PARAM_set_ulong(OSSL_PARAM *p, unsigned long int val)
160 switch (sizeof(unsigned long int)) {
161 case sizeof(uint32_t):
162 return OSSL_PARAM_set_uint32(p, (uint32_t)val);
163 case sizeof(uint64_t):
164 return OSSL_PARAM_set_uint64(p, (uint64_t)val);
169 OSSL_PARAM OSSL_PARAM_construct_ulong(const char *key, unsigned long int *buf)
171 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER, buf,
172 sizeof(unsigned long int));
175 int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val)
182 if (val == NULL || p == NULL )
185 if (p->data_type == OSSL_PARAM_INTEGER) {
186 switch (p->data_size) {
187 case sizeof(int32_t):
188 *val = *(const int32_t *)p->data;
190 case sizeof(int64_t):
191 i64 = *(const int64_t *)p->data;
192 if (i64 >= INT32_MIN && i64 <= INT32_MAX) {
198 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
199 switch (p->data_size) {
200 case sizeof(uint32_t):
201 u32 = *(const uint32_t *)p->data;
202 if (u32 <= INT32_MAX) {
207 case sizeof(uint64_t):
208 u64 = *(const uint64_t *)p->data;
209 if (u64 <= INT32_MAX) {
215 } else if (p->data_type == OSSL_PARAM_REAL) {
216 switch (p->data_size) {
218 d = *(const double *)p->data;
219 if (d >= INT32_MIN && d <= INT32_MAX && d == (int32_t)d) {
229 int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val)
234 if (p->data_type == OSSL_PARAM_INTEGER) {
235 p->return_size = sizeof(int32_t); /* Minimum expected size */
238 switch (p->data_size) {
239 case sizeof(int32_t):
240 *(int32_t *)p->data = val;
242 case sizeof(int64_t):
243 p->return_size = sizeof(int64_t);
244 *(int64_t *)p->data = (int64_t)val;
247 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER && val >= 0) {
248 p->return_size = sizeof(uint32_t); /* Minimum expected size */
251 switch (p->data_size) {
252 case sizeof(uint32_t):
253 *(uint32_t *)p->data = (uint32_t)val;
255 case sizeof(uint64_t):
256 p->return_size = sizeof(uint64_t);
257 *(uint64_t *)p->data = (uint64_t)val;
260 } else if (p->data_type == OSSL_PARAM_REAL) {
261 p->return_size = sizeof(double);
264 switch (p->data_size) {
266 *(double *)p->data = (double)val;
273 OSSL_PARAM OSSL_PARAM_construct_int32(const char *key, int32_t *buf)
275 return ossl_param_construct(key, OSSL_PARAM_INTEGER, buf,
279 int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val)
286 if (val == NULL || p == NULL)
289 if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
290 switch (p->data_size) {
291 case sizeof(uint32_t):
292 *val = *(const uint32_t *)p->data;
294 case sizeof(uint64_t):
295 u64 = *(const uint64_t *)p->data;
296 if (u64 <= UINT32_MAX) {
297 *val = (uint32_t)u64;
302 } else if (p->data_type == OSSL_PARAM_INTEGER) {
303 switch (p->data_size) {
304 case sizeof(int32_t):
305 i32 = *(const int32_t *)p->data;
311 case sizeof(int64_t):
312 i64 = *(const int64_t *)p->data;
313 if (i64 >= 0 && i64 <= UINT32_MAX) {
314 *val = (uint32_t)i64;
319 } else if (p->data_type == OSSL_PARAM_REAL) {
320 switch (p->data_size) {
322 d = *(const double *)p->data;
323 if (d >= 0 && d <= UINT32_MAX && d == (uint32_t)d) {
333 int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val)
339 if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
340 p->return_size = sizeof(uint32_t); /* Minimum expected size */
343 switch (p->data_size) {
344 case sizeof(uint32_t):
345 *(uint32_t *)p->data = val;
347 case sizeof(uint64_t):
348 p->return_size = sizeof(uint64_t);
349 *(uint64_t *)p->data = val;
352 } else if (p->data_type == OSSL_PARAM_INTEGER) {
353 p->return_size = sizeof(int32_t); /* Minimum expected size */
356 switch (p->data_size) {
357 case sizeof(int32_t):
358 if (val <= INT32_MAX) {
359 *(int32_t *)p->data = (int32_t)val;
363 case sizeof(int64_t):
364 p->return_size = sizeof(int64_t);
365 *(int64_t *)p->data = (int64_t)val;
368 } else if (p->data_type == OSSL_PARAM_REAL) {
369 p->return_size = sizeof(double);
372 switch (p->data_size) {
374 *(double *)p->data = (double)val;
381 OSSL_PARAM OSSL_PARAM_construct_uint32(const char *key, uint32_t *buf)
383 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER, buf,
387 int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val)
392 if (val == NULL || p == NULL )
395 if (p->data_type == OSSL_PARAM_INTEGER) {
396 switch (p->data_size) {
397 case sizeof(int32_t):
398 *val = *(const int32_t *)p->data;
400 case sizeof(int64_t):
401 *val = *(const int64_t *)p->data;
404 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
405 switch (p->data_size) {
406 case sizeof(uint32_t):
407 *val = *(const uint32_t *)p->data;
409 case sizeof(uint64_t):
410 u64 = *(const uint64_t *)p->data;
411 if (u64 <= INT64_MAX) {
417 } else if (p->data_type == OSSL_PARAM_REAL) {
418 switch (p->data_size) {
420 d = *(const double *)p->data;
423 * By subtracting 65535 (2^16-1) we cancel the low order
424 * 15 bits of INT64_MAX to avoid using imprecise floating
427 && d < (double)(INT64_MAX - 65535) + 65536.0
428 && d == (int64_t)d) {
438 int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val)
445 if (p->data_type == OSSL_PARAM_INTEGER) {
446 p->return_size = sizeof(int64_t); /* Expected size */
449 switch (p->data_size) {
450 case sizeof(int32_t):
451 if (val >= INT32_MIN && val <= INT32_MAX) {
452 p->return_size = sizeof(int32_t);
453 *(int32_t *)p->data = (int32_t)val;
457 case sizeof(int64_t):
458 *(int64_t *)p->data = val;
461 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER && val >= 0) {
462 p->return_size = sizeof(uint64_t); /* Expected size */
465 switch (p->data_size) {
466 case sizeof(uint32_t):
467 if (val <= UINT32_MAX) {
468 p->return_size = sizeof(uint32_t);
469 *(uint32_t *)p->data = (uint32_t)val;
473 case sizeof(uint64_t):
474 *(uint64_t *)p->data = (uint64_t)val;
477 } else if (p->data_type == OSSL_PARAM_REAL) {
478 p->return_size = sizeof(double);
481 switch (p->data_size) {
483 u64 = val < 0 ? -val : val;
484 if ((u64 >> real_shift()) == 0) {
485 *(double *)p->data = (double)val;
494 OSSL_PARAM OSSL_PARAM_construct_int64(const char *key, int64_t *buf)
496 return ossl_param_construct(key, OSSL_PARAM_INTEGER, buf, sizeof(int64_t));
499 int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val)
505 if (val == NULL || p == NULL)
508 if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
509 switch (p->data_size) {
510 case sizeof(uint32_t):
511 *val = *(const uint32_t *)p->data;
513 case sizeof(uint64_t):
514 *val = *(const uint64_t *)p->data;
517 } else if (p->data_type == OSSL_PARAM_INTEGER) {
518 switch (p->data_size) {
519 case sizeof(int32_t):
520 i32 = *(const int32_t *)p->data;
522 *val = (uint64_t)i32;
526 case sizeof(int64_t):
527 i64 = *(const int64_t *)p->data;
529 *val = (uint64_t)i64;
534 } else if (p->data_type == OSSL_PARAM_REAL) {
535 switch (p->data_size) {
537 d = *(const double *)p->data;
540 * By subtracting 65535 (2^16-1) we cancel the low order
541 * 15 bits of UINT64_MAX to avoid using imprecise floating
544 && d < (double)(UINT64_MAX - 65535) + 65536.0
545 && d == (uint64_t)d) {
555 int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val)
561 if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
562 p->return_size = sizeof(uint64_t); /* Expected size */
565 switch (p->data_size) {
566 case sizeof(uint32_t):
567 if (val <= UINT32_MAX) {
568 p->return_size = sizeof(uint32_t);
569 *(uint32_t *)p->data = (uint32_t)val;
573 case sizeof(uint64_t):
574 *(uint64_t *)p->data = val;
577 } else if (p->data_type == OSSL_PARAM_INTEGER) {
578 p->return_size = sizeof(int64_t); /* Expected size */
581 switch (p->data_size) {
582 case sizeof(int32_t):
583 if (val <= INT32_MAX) {
584 p->return_size = sizeof(int32_t);
585 *(int32_t *)p->data = (int32_t)val;
589 case sizeof(int64_t):
590 if (val <= INT64_MAX) {
591 *(int64_t *)p->data = (int64_t)val;
596 } else if (p->data_type == OSSL_PARAM_REAL) {
597 p->return_size = sizeof(double);
598 switch (p->data_size) {
600 if ((val >> real_shift()) == 0) {
601 *(double *)p->data = (double)val;
610 OSSL_PARAM OSSL_PARAM_construct_uint64(const char *key, uint64_t *buf)
612 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER, buf,
616 int OSSL_PARAM_get_size_t(const OSSL_PARAM *p, size_t *val)
618 switch (sizeof(size_t)) {
619 case sizeof(uint32_t):
620 return OSSL_PARAM_get_uint32(p, (uint32_t *)val);
621 case sizeof(uint64_t):
622 return OSSL_PARAM_get_uint64(p, (uint64_t *)val);
627 int OSSL_PARAM_set_size_t(OSSL_PARAM *p, size_t val)
629 switch (sizeof(size_t)) {
630 case sizeof(uint32_t):
631 return OSSL_PARAM_set_uint32(p, (uint32_t)val);
632 case sizeof(uint64_t):
633 return OSSL_PARAM_set_uint64(p, (uint64_t)val);
638 OSSL_PARAM OSSL_PARAM_construct_size_t(const char *key, size_t *buf)
640 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER, buf,
644 int OSSL_PARAM_get_time_t(const OSSL_PARAM *p, time_t *val)
646 switch (sizeof(time_t)) {
647 case sizeof(int32_t):
648 return OSSL_PARAM_get_int32(p, (int32_t *)val);
649 case sizeof(int64_t):
650 return OSSL_PARAM_get_int64(p, (int64_t *)val);
655 int OSSL_PARAM_set_time_t(OSSL_PARAM *p, time_t val)
657 switch (sizeof(time_t)) {
658 case sizeof(int32_t):
659 return OSSL_PARAM_set_int32(p, (int32_t)val);
660 case sizeof(int64_t):
661 return OSSL_PARAM_set_int64(p, (int64_t)val);
666 OSSL_PARAM OSSL_PARAM_construct_time_t(const char *key, time_t *buf)
668 return ossl_param_construct(key, OSSL_PARAM_INTEGER, buf, sizeof(time_t));
671 int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val)
677 || p->data_type != OSSL_PARAM_UNSIGNED_INTEGER)
680 b = BN_native2bn(p->data, (int)p->data_size, *val);
688 int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val)
695 if (val == NULL || p->data_type != OSSL_PARAM_UNSIGNED_INTEGER)
698 /* For the moment, only positive values are permitted */
699 if (BN_is_negative(val))
702 bytes = (size_t)BN_num_bytes(val);
703 p->return_size = bytes;
706 if (p->data_size >= bytes) {
707 p->return_size = p->data_size;
708 return BN_bn2nativepad(val, p->data, p->data_size) >= 0;
713 OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
716 return ossl_param_construct(key, OSSL_PARAM_UNSIGNED_INTEGER,
720 int OSSL_PARAM_get_double(const OSSL_PARAM *p, double *val)
725 if (val == NULL || p == NULL)
728 if (p->data_type == OSSL_PARAM_REAL) {
729 switch (p->data_size) {
731 *val = *(const double *)p->data;
734 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
735 switch (p->data_size) {
736 case sizeof(uint32_t):
737 *val = *(const uint32_t *)p->data;
739 case sizeof(uint64_t):
740 u64 = *(const uint64_t *)p->data;
741 if ((u64 >> real_shift()) == 0) {
747 } else if (p->data_type == OSSL_PARAM_INTEGER) {
748 switch (p->data_size) {
749 case sizeof(int32_t):
750 *val = *(const int32_t *)p->data;
752 case sizeof(int64_t):
753 i64 = *(const int64_t *)p->data;
754 u64 = i64 < 0 ? -i64 : i64;
755 if ((u64 >> real_shift()) == 0) {
765 int OSSL_PARAM_set_double(OSSL_PARAM *p, double val)
771 if (p->data_type == OSSL_PARAM_REAL) {
772 p->return_size = sizeof(double);
775 switch (p->data_size) {
777 *(double *)p->data = val;
780 } else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER
781 && val == (ossl_uintmax_t)val) {
782 p->return_size = sizeof(double);
785 switch (p->data_size) {
786 case sizeof(uint32_t):
787 if (val >= 0 && val <= UINT32_MAX) {
788 p->return_size = sizeof(uint32_t);
789 *(uint32_t *)p->data = (uint32_t)val;
793 case sizeof(uint64_t):
796 * By subtracting 65535 (2^16-1) we cancel the low order
797 * 15 bits of UINT64_MAX to avoid using imprecise floating
800 && (double)(UINT64_MAX - 65535) + 65536.0) {
801 p->return_size = sizeof(uint64_t);
802 *(uint64_t *)p->data = (uint64_t)val;
806 } else if (p->data_type == OSSL_PARAM_INTEGER && val == (ossl_intmax_t)val) {
807 p->return_size = sizeof(double);
810 switch (p->data_size) {
811 case sizeof(int32_t):
812 if (val >= INT32_MIN && val <= INT32_MAX) {
813 p->return_size = sizeof(int32_t);
814 *(int32_t *)p->data = (int32_t)val;
818 case sizeof(int64_t):
821 * By subtracting 65535 (2^16-1) we cancel the low order
822 * 15 bits of INT64_MAX to avoid using imprecise floating
825 && val < (double)(INT64_MAX - 65535) + 65536.0) {
826 p->return_size = sizeof(int64_t);
827 *(int64_t *)p->data = (int64_t)val;
836 OSSL_PARAM OSSL_PARAM_construct_double(const char *key, double *buf)
838 return ossl_param_construct(key, OSSL_PARAM_REAL, buf, sizeof(double));
841 static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len,
842 size_t *used_len, unsigned int type)
846 if ((val == NULL && used_len == NULL) || p == NULL || p->data_type != type)
851 if (used_len != NULL)
861 char *const q = OPENSSL_malloc(sz > 0 ? sz : 1);
867 memcpy(q, p->data, sz);
872 memcpy(*val, p->data, sz);
876 int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val, size_t max_len)
878 return get_string_internal(p, (void **)val, max_len, NULL,
879 OSSL_PARAM_UTF8_STRING);
882 int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val, size_t max_len,
885 return get_string_internal(p, val, max_len, used_len,
886 OSSL_PARAM_OCTET_STRING);
889 static int set_string_internal(OSSL_PARAM *p, const void *val, size_t len,
892 p->return_size = len;
895 if (p->data_type != type || p->data_size < len)
898 memcpy(p->data, val, len);
902 int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val)
910 return set_string_internal(p, val, strlen(val) + 1, OSSL_PARAM_UTF8_STRING);
913 int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val,
922 return set_string_internal(p, val, len, OSSL_PARAM_OCTET_STRING);
925 OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
928 if (buf != NULL && bsize == 0)
929 bsize = strlen(buf) + 1;
930 return ossl_param_construct(key, OSSL_PARAM_UTF8_STRING, buf, bsize);
933 OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
936 return ossl_param_construct(key, OSSL_PARAM_OCTET_STRING, buf, bsize);
939 static int get_ptr_internal(const OSSL_PARAM *p, const void **val,
940 size_t *used_len, unsigned int type)
942 if (val == NULL || p == NULL || p->data_type != type)
944 if (used_len != NULL)
945 *used_len = p->data_size;
946 *val = *(const void **)p->data;
950 int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val)
952 return get_ptr_internal(p, (const void **)val, NULL, OSSL_PARAM_UTF8_PTR);
955 int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
958 return get_ptr_internal(p, val, used_len, OSSL_PARAM_OCTET_PTR);
961 static int set_ptr_internal(OSSL_PARAM *p, const void *val,
962 unsigned int type, size_t len)
964 p->return_size = len;
965 if (p->data_type != type)
968 *(const void **)p->data = val;
972 int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val)
977 return set_ptr_internal(p, val, OSSL_PARAM_UTF8_PTR,
978 val == NULL ? 0 : strlen(val) + 1);
981 int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
987 return set_ptr_internal(p, val, OSSL_PARAM_OCTET_PTR, used_len);
990 OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
993 return ossl_param_construct(key, OSSL_PARAM_UTF8_PTR, buf, bsize);
996 OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
999 return ossl_param_construct(key, OSSL_PARAM_OCTET_PTR, buf, bsize);
1002 OSSL_PARAM OSSL_PARAM_construct_end(void)
1004 OSSL_PARAM end = OSSL_PARAM_END;
1009 static int get_string_ptr_internal(const OSSL_PARAM *p, const void **val,
1010 size_t *used_len, unsigned int type)
1012 if (val == NULL || p == NULL || p->data_type != type)
1014 if (used_len != NULL)
1015 *used_len = p->data_size;
1020 int OSSL_PARAM_get_utf8_string_ptr(const OSSL_PARAM *p, const char **val)
1022 return OSSL_PARAM_get_utf8_ptr(p, val)
1023 || get_string_ptr_internal(p, (const void **)val, NULL,
1024 OSSL_PARAM_UTF8_STRING);
1027 int OSSL_PARAM_get_octet_string_ptr(const OSSL_PARAM *p, const void **val,
1030 return OSSL_PARAM_get_octet_ptr(p, val, used_len)
1031 || get_string_ptr_internal(p, val, used_len, OSSL_PARAM_OCTET_STRING);