/*
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/params.h>
#include "internal/thread_once.h"
#include "internal/numbers.h"
#include "internal/endian.h"
/*
* Return the number of bits in the mantissa of a double. This is used to
* shift a larger integral value to determine if it will exactly fit into a
* double.
*/
static unsigned int real_shift(void)
{
return sizeof(double) == 4 ? 24 : 53;
}
OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *p, const char *key)
{
if (p != NULL && key != NULL)
for (; p->key != NULL; p++)
if (strcmp(key, p->key) == 0)
return p;
return NULL;
}
const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *p, const char *key)
{
return OSSL_PARAM_locate((OSSL_PARAM *)p, key);
}
static OSSL_PARAM ossl_param_construct(const char *key, unsigned int data_type,
void *data, size_t data_size)
{
OSSL_PARAM res;
res.key = key;
res.data_type = data_type;
res.data = data;
res.data_size = data_size;
res.return_size = OSSL_PARAM_UNMODIFIED;
return res;
}
int OSSL_PARAM_modified(const OSSL_PARAM *p)
{
return p != NULL && p->return_size != OSSL_PARAM_UNMODIFIED;
}
void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p)
{
if (p != NULL)
while (p->key != NULL)
p++->return_size = OSSL_PARAM_UNMODIFIED;
}
/* Return non-zero if the signed number is negative */
static int is_negative(const void *number, size_t s)
{
const unsigned char *n