#include "crypto/cryptoerr.h"
#include "crypto/asn1err.h"
#include "crypto/bnerr.h"
+#include "crypto/fnerr.h"
#include "crypto/ecerr.h"
#include "crypto/buffererr.h"
#include "crypto/bioerr.h"
#ifndef OPENSSL_NO_ERR
|| ossl_err_load_ERR_strings() == 0 /* include error strings for SYSerr */
|| ossl_err_load_BN_strings() == 0
+ || ossl_err_load_OSSL_FN_strings() == 0
|| ossl_err_load_RSA_strings() == 0
#ifndef OPENSSL_NO_DH
|| ossl_err_load_DH_strings() == 0
L OSSL_ENCODER include/openssl/encodererr.h crypto/encode_decode/encoder_err.c include/crypto/encodererr.h
L OSSL_DECODER include/openssl/decodererr.h crypto/encode_decode/decoder_err.c include/crypto/decodererr.h
L HTTP include/openssl/httperr.h crypto/http/http_err.c include/crypto/httperr.h
+L OSSL_FN NONE crypto/fn/fn_err.c include/crypto/fnerr.h
# SSL/TLS alerts
R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
OSSL_ENCODER_R_ENCODER_NOT_FOUND:101:encoder not found
OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY:100:incorrect property query
OSSL_ENCODER_R_MISSING_GET_PARAMS:102:missing get params
+OSSL_FN_R_RESULT_ARG_TOO_SMALL:100:result arg too small
OSSL_STORE_R_AMBIGUOUS_CONTENT_TYPE:107:ambiguous content type
OSSL_STORE_R_BAD_PASSWORD_READ:115:bad password read
OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC:113:error verifying pkcs12 mac
$LIBFIPS=../../providers/libfips.a
LIBS=$LIBCRYPTO
-$COMMON=fn_lib.c
+$COMMON=fn_err.c fn_lib.c fn_intern.c
SOURCE[$LIBCRYPTO]=$COMMON
SOURCE[$LIBFIPS]=$COMMON
--- /dev/null
+/*
+ * Generated by util/mkerr.pl DO NOT EDIT
+ * Copyright 1995-2025 The OpenSSL Project Authors. 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 <openssl/err.h>
+#include "crypto/fnerr.h"
+
+#ifndef OPENSSL_NO_ERR
+
+static const ERR_STRING_DATA OSSL_FN_str_reasons[] = {
+ { ERR_PACK(ERR_LIB_OSSL_FN, 0, OSSL_FN_R_RESULT_ARG_TOO_SMALL),
+ "result arg too small" },
+ { 0, NULL }
+};
+
+#endif
+
+int ossl_err_load_OSSL_FN_strings(void)
+{
+#ifndef OPENSSL_NO_ERR
+ if (ERR_reason_error_string(OSSL_FN_str_reasons[0].error) == NULL)
+ ERR_load_strings_const(OSSL_FN_str_reasons);
+#endif
+ return 1;
+}
--- /dev/null
+/*
+ * Copyright 2025 The OpenSSL Project Authors. 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 "internal/cryptlib.h"
+#include "crypto/fn_intern.h"
+#include "crypto/fnerr.h"
+#include "fn_local.h"
+#include <openssl/err.h>
+
+int ossl_fn_set_words(OSSL_FN *f, const OSSL_FN_ULONG *words, size_t limbs)
+{
+ if (ossl_unlikely(f == NULL)) {
+ ERR_raise(ERR_LIB_OSSL_FN, ERR_R_PASSED_NULL_PARAMETER);
+ return 0;
+ }
+
+ if ((size_t)f->dsize < limbs) {
+ ERR_raise(ERR_LIB_OSSL_FN, OSSL_FN_R_RESULT_ARG_TOO_SMALL);
+ return 0;
+ }
+
+ memcpy(f->d, words, sizeof(OSSL_FN_ULONG) * limbs);
+ memset(f->d + limbs, 0, sizeof(OSSL_FN_ULONG) * (f->dsize - limbs));
+ return 1;
+}
+
+const OSSL_FN_ULONG *ossl_fn_get_words(OSSL_FN *f)
+{
+ if (ossl_unlikely(f == NULL)) {
+ ERR_raise(ERR_LIB_OSSL_FN, ERR_R_PASSED_NULL_PARAMETER);
+ return NULL;
+ }
+
+ return f->d;
+}
+
+size_t ossl_fn_get_dsize(OSSL_FN *f)
+{
+ return f->dsize;
+}
+
+bool ossl_fn_is_dynamically_allocated(OSSL_FN *f)
+{
+ return f->is_dynamically_allocated;
+}
+
+bool ossl_fn_is_securely_allocated(OSSL_FN *f)
+{
+ return f->is_securely_allocated;
+}
#include <openssl/e_os2.h>
#include "internal/common.h"
#include "crypto/fn.h"
+#include "crypto/fn_intern.h"
+
+#if OSSL_FN_BYTES == 4
+/* 32-bit systems */
+#define OSSL_FN_MASK UINT32_MAX
+#elif OSSL_FN_BYTES == 8
+/* 64-bit systems */
+#define OSSL_FN_MASK UINT64_MAX
+#else
+#error "OpenSSL doesn't support large numbers on this platform"
+#endif
+
+#define OSSL_FN_HIGH_BIT_MASK (OSSL_FN_ULONG_C(1) << (OSSL_FN_BYTES * 8 - 1))
struct ossl_fn_st {
/* Flag: alloced with OSSL_FN_new() or OSSL_FN_secure_new() */
--- /dev/null
+/*
+ * Copyright 2025 The OpenSSL Project Authors. 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
+ */
+
+/**
+ * @file A set of internal functions to manipulate the OSSL_FN d array, and
+ * for introspection.
+ */
+
+#ifndef OPENSSL_FN_INTERN_H
+#define OPENSSL_FN_INTERN_H
+#pragma once
+
+#include <stdbool.h>
+#include "crypto/fn.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if OSSL_FN_BYTES == 4
+/* 32-bit systems */
+#define OSSL_FN_ULONG_C(n) UINT32_C(n)
+#define OSSL_FN_ULONG64_C(hi32, lo32) OSSL_FN_ULONG_C(lo32), OSSL_FN_ULONG_C(hi32)
+#elif OSSL_FN_BYTES == 8
+/* 64-bit systems */
+#define OSSL_FN_ULONG_C(n) UINT64_C(n)
+#define OSSL_FN_ULONG64_C(hi32, lo32) (OSSL_FN_ULONG_C(hi32) << 32 | OSSL_FN_ULONG_C(lo32))
+#else
+#error "OpenSSL doesn't support large numbers on this platform"
+#endif
+
+int ossl_fn_set_words(OSSL_FN *f, const OSSL_FN_ULONG *words, size_t limbs);
+const OSSL_FN_ULONG *ossl_fn_get_words(OSSL_FN *f);
+
+size_t ossl_fn_get_dsize(OSSL_FN *f);
+
+void ossl_fn_set_negative(OSSL_FN *f, bool neg);
+
+bool ossl_fn_is_negative(OSSL_FN *f);
+bool ossl_fn_is_dynamically_allocated(OSSL_FN *f);
+bool ossl_fn_is_securely_allocated(OSSL_FN *f);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/*
+ * Generated by util/mkerr.pl DO NOT EDIT
+ * Copyright 2020-2025 The OpenSSL Project Authors. 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
+ */
+
+#ifndef OSSL_CRYPTO_FNERR_H
+#define OSSL_CRYPTO_FNERR_H
+#pragma once
+
+#include <openssl/opensslconf.h>
+#include <openssl/symhacks.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ossl_err_load_OSSL_FN_strings(void);
+
+/*
+ * OSSL_FN reason codes.
+ */
+#define OSSL_FN_R_RESULT_ARG_TOO_SMALL 100
+
+#ifdef __cplusplus
+}
+#endif
+#endif
#define ERR_LIB_OSSL_ENCODER 59
#define ERR_LIB_OSSL_DECODER 60
#define ERR_LIB_HTTP 61
+#define ERR_LIB_OSSL_FN 62
#define ERR_LIB_USER 128
*/
#include "crypto/fn.h"
+#include "crypto/fn_intern.h"
#include "fn_local.h"
#include "testutil.h"
{
int ret = 1;
OSSL_FN *f = NULL;
+ const OSSL_FN_ULONG *u = NULL;
/*
* OSSL_FN_new_bits() calls OSSL_FN_new_bytes(), which calls
* shaving off 17 bits for demonstration purposes.
*/
if (!TEST_ptr(f = OSSL_FN_new_bits(sizeof(OSSL_FN_ULONG) * 16 - 17))
- || !TEST_uint_eq(f->is_dynamically_allocated, 1)
- || !TEST_uint_eq(f->is_securely_allocated, 0)
- || !TEST_int_eq(f->dsize, 2)
- || !TEST_size_t_eq(f->d[0], 0)
- || !TEST_size_t_eq(f->d[1], 0))
+ || !TEST_true(ossl_fn_is_dynamically_allocated(f))
+ || !TEST_false(ossl_fn_is_securely_allocated(f))
+ || !TEST_size_t_eq(ossl_fn_get_dsize(f), 2)
+ || !TEST_ptr(u = ossl_fn_get_words(f))
+ || !TEST_size_t_eq(u[0], 0)
+ || !TEST_size_t_eq(u[1], 0))
ret = 0;
OSSL_FN_free(f);
{
int ret = 1;
OSSL_FN *f = NULL;
+ const OSSL_FN_ULONG *u = NULL;
/*
* OSSL_FN_secure_new_bits() calls OSSL_FN_secure_new_bytes(), which calls
* shaving off 17 bits for demonstration purposes.
*/
if (!TEST_ptr(f = OSSL_FN_secure_new_bits(sizeof(OSSL_FN_ULONG) * 16 - 17))
- || !TEST_uint_eq(f->is_dynamically_allocated, 1)
- || !TEST_uint_eq(f->is_securely_allocated, 1)
- || !TEST_int_eq(f->dsize, 2)
- || !TEST_size_t_eq(f->d[0], 0)
- || !TEST_size_t_eq(f->d[1], 0))
+ || !TEST_true(ossl_fn_is_dynamically_allocated(f))
+ || !TEST_true(ossl_fn_is_securely_allocated(f))
+ || !TEST_size_t_eq(ossl_fn_get_dsize(f), 2)
+ || !TEST_ptr(u = ossl_fn_get_words(f))
+ || !TEST_size_t_eq(u[0], 0)
+ || !TEST_size_t_eq(u[1], 0))
ret = 0;
OSSL_FN_free(f);