Skip to content

Commit

Permalink
crypto/params: drop float for UEFI
Browse files Browse the repository at this point in the history
Using floating point is not supported in UEFI and can cause build
problems, for example due to SSE being disabled and x64 calling
convention passing floats in SSE registers.

Avoid those problems by not compiling the related code for floating
point numbers.

Signed-off-by: Yi Li <yi1.li@intel.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #20992)
  • Loading branch information
liyi77 authored and hlandau committed May 22, 2023
1 parent f3afe15 commit 2c50057
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions crypto/params.c
Expand Up @@ -38,6 +38,7 @@
#define err_unsupported_real \
ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_PARAM_UNSUPPORTED_FLOATING_POINT_FORMAT)

#ifndef OPENSSL_SYS_UEFI
/*
* 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
Expand All @@ -47,6 +48,7 @@ static unsigned int real_shift(void)
{
return sizeof(double) == 4 ? 24 : 53;
}
#endif

OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *p, const char *key)
{
Expand Down Expand Up @@ -378,8 +380,6 @@ OSSL_PARAM OSSL_PARAM_construct_ulong(const char *key, unsigned long int *buf)

int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val)
{
double d;

if (val == NULL || p == NULL) {
err_null_argument;
return 0;
Expand Down Expand Up @@ -432,6 +432,9 @@ int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val)
return general_get_int(p, val, sizeof(*val));

} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
double d;

switch (p->data_size) {
case sizeof(double):
d = *(const double *)p->data;
Expand All @@ -444,6 +447,7 @@ int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand Down Expand Up @@ -492,6 +496,7 @@ int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val)
#endif
return general_set_int(p, &val, sizeof(val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
p->return_size = sizeof(double);
if (p->data == NULL)
return 1;
Expand All @@ -510,6 +515,7 @@ int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand All @@ -523,8 +529,6 @@ OSSL_PARAM OSSL_PARAM_construct_int32(const char *key, int32_t *buf)

int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val)
{
double d;

if (val == NULL || p == NULL) {
err_null_argument;
return 0;
Expand Down Expand Up @@ -578,6 +582,9 @@ int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val)
#endif
return general_get_uint(p, val, sizeof(*val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
double d;

switch (p->data_size) {
case sizeof(double):
d = *(const double *)p->data;
Expand All @@ -590,6 +597,7 @@ int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand Down Expand Up @@ -642,6 +650,7 @@ int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val)
#endif
return general_set_uint(p, &val, sizeof(val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
p->return_size = sizeof(double);
if (p->data == NULL)
return 1;
Expand All @@ -657,6 +666,7 @@ int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand All @@ -670,8 +680,6 @@ OSSL_PARAM OSSL_PARAM_construct_uint32(const char *key, uint32_t *buf)

int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val)
{
double d;

if (val == NULL || p == NULL) {
err_null_argument;
return 0;
Expand Down Expand Up @@ -709,6 +717,9 @@ int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val)
#endif
return general_get_int(p, val, sizeof(*val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
double d;

switch (p->data_size) {
case sizeof(double):
d = *(const double *)p->data;
Expand All @@ -728,15 +739,14 @@ int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
}

int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val)
{
uint64_t u64;

if (p == NULL) {
err_null_argument;
return 0;
Expand Down Expand Up @@ -783,6 +793,9 @@ int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val)
#endif
return general_set_int(p, &val, sizeof(val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
uint64_t u64;

p->return_size = sizeof(double);
if (p->data == NULL)
return 1;
Expand All @@ -798,6 +811,7 @@ int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand All @@ -810,8 +824,6 @@ OSSL_PARAM OSSL_PARAM_construct_int64(const char *key, int64_t *buf)

int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val)
{
double d;

if (val == NULL || p == NULL) {
err_null_argument;
return 0;
Expand Down Expand Up @@ -855,6 +867,9 @@ int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val)
#endif
return general_get_uint(p, val, sizeof(*val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
double d;

switch (p->data_size) {
case sizeof(double):
d = *(const double *)p->data;
Expand All @@ -874,6 +889,7 @@ int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand Down Expand Up @@ -932,6 +948,7 @@ int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val)
#endif
return general_set_uint(p, &val, sizeof(val));
} else if (p->data_type == OSSL_PARAM_REAL) {
#ifndef OPENSSL_SYS_UEFI
p->return_size = sizeof(double);
switch (p->data_size) {
case sizeof(double):
Expand All @@ -944,6 +961,7 @@ int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val)
}
err_unsupported_real;
return 0;
#endif
}
err_bad_type;
return 0;
Expand Down Expand Up @@ -1108,6 +1126,7 @@ OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
buf, bsize);
}

#ifndef OPENSSL_SYS_UEFI
int OSSL_PARAM_get_double(const OSSL_PARAM *p, double *val)
{
int64_t i64;
Expand Down Expand Up @@ -1252,6 +1271,7 @@ OSSL_PARAM OSSL_PARAM_construct_double(const char *key, double *buf)
{
return ossl_param_construct(key, OSSL_PARAM_REAL, buf, sizeof(double));
}
#endif

static int get_string_internal(const OSSL_PARAM *p, void **val,
size_t *max_len, size_t *used_len,
Expand Down

0 comments on commit 2c50057

Please sign in to comment.