Coverage Report

Created: 2026-04-28 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/ec/curve448/word.h
Line
Count
Source
1
/*
2
 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright 2014 Cryptography Research, Inc.
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
 * Originally written by Mike Hamburg
11
 */
12
13
#ifndef OSSL_CRYPTO_EC_CURVE448_WORD_H
14
#define OSSL_CRYPTO_EC_CURVE448_WORD_H
15
16
#include <string.h>
17
#include <assert.h>
18
#include <stdlib.h>
19
#include <openssl/e_os2.h>
20
#include "curve448utils.h"
21
#include "internal/constant_time.h"
22
23
#ifdef INT128_MAX
24
#include "arch_64/arch_intrinsics.h"
25
#else
26
#include "arch_32/arch_intrinsics.h"
27
#endif
28
29
#if (ARCH_WORD_BITS == 64)
30
typedef uint64_t word_t, mask_t;
31
typedef uint128_t dword_t;
32
typedef int32_t hsword_t;
33
typedef int64_t sword_t;
34
typedef int128_t dsword_t;
35
#elif (ARCH_WORD_BITS == 32)
36
typedef uint32_t word_t, mask_t;
37
typedef uint64_t dword_t;
38
typedef int16_t hsword_t;
39
typedef int32_t sword_t;
40
typedef int64_t dsword_t;
41
#else
42
#error "For now, we only support 32- and 64-bit architectures."
43
#endif
44
45
/*
46
 * Scalar limbs are keyed off of the API word size instead of the arch word
47
 * size.
48
 */
49
#if C448_WORD_BITS == 64
50
#define SC_LIMB(x) (x)
51
#elif C448_WORD_BITS == 32
52
#define SC_LIMB(x) ((uint32_t)(x)), ((x) >> 32)
53
#else
54
#error "For now we only support 32- and 64-bit architectures."
55
#endif
56
57
#if C448_WORD_BITS == 64
58
0
#define value_barrier_c448(x) value_barrier_64(x)
59
#elif C448_WORD_BITS == 32
60
#define value_barrier_c448(x) value_barrier_32(x)
61
#endif
62
63
/*
64
 * The plan on booleans: The external interface uses c448_bool_t, but this
65
 * might be a different size than our particular arch's word_t (and thus
66
 * mask_t).  Also, the caller isn't guaranteed to pass it as nonzero.  So
67
 * bool_to_mask converts word sizes and checks nonzero. On the flip side,
68
 * mask_t is always -1 or 0, but it might be a different size than
69
 * c448_bool_t. On the third hand, we have success vs boolean types, but
70
 * that's handled in common.h: it converts between c448_bool_t and
71
 * c448_error_t.
72
 */
73
static ossl_inline c448_bool_t mask_to_bool(mask_t m)
74
0
{
75
0
    return (c448_sword_t)(sword_t)m;
76
0
}
Unexecuted instantiation: curve448.c:mask_to_bool
Unexecuted instantiation: curve448_tables.c:mask_to_bool
Unexecuted instantiation: eddsa.c:mask_to_bool
Unexecuted instantiation: f_generic.c:mask_to_bool
Unexecuted instantiation: scalar.c:mask_to_bool
Unexecuted instantiation: f_impl64.c:mask_to_bool
77
78
static ossl_inline mask_t bool_to_mask(c448_bool_t m)
79
0
{
80
0
    /* On most arches this will be optimized to a simple cast. */
81
0
    mask_t ret = 0;
82
0
    unsigned int i;
83
0
    unsigned int limit = sizeof(c448_bool_t) / sizeof(mask_t);
84
0
85
0
    if (limit < 1)
86
0
        limit = 1;
87
0
    for (i = 0; i < limit; i++)
88
0
        ret |= ~word_is_zero(m >> (i * 8 * sizeof(word_t)));
89
0
90
0
    return ret;
91
0
}
Unexecuted instantiation: curve448.c:bool_to_mask
Unexecuted instantiation: curve448_tables.c:bool_to_mask
Unexecuted instantiation: eddsa.c:bool_to_mask
Unexecuted instantiation: f_generic.c:bool_to_mask
Unexecuted instantiation: scalar.c:bool_to_mask
Unexecuted instantiation: f_impl64.c:bool_to_mask
92
93
#endif /* OSSL_CRYPTO_EC_CURVE448_WORD_H */