• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hpsc-lab / SecureArithmetic.jl / 17397120271

02 Sep 2025 07:58AM UTC coverage: 96.854%. Remained the same
17397120271

push

github

web-flow
Bump actions/checkout from 4 to 5 (#80)

Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

585 of 604 relevant lines covered (96.85%)

561.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.28
/src/unencrypted.jl
1
"""
2
    Unencrypted
3

4
An alternative backend to use instead of [`OpenFHEBackend`](@ref) to experiment with
5
algorithms on unencrypted data.
6

7
See also: [`SecureContext`](@ref), [`OpenFHEBackend`](@ref)
8
"""
9
struct Unencrypted <: AbstractCryptoBackend
50✔
10
    # No data fields required
11
end
12

13
"""
14
    generate_keys(context::SecureContext{<:Unencrypted})
15

16
Return public and private keys for use with unencrypted data.
17

18
See also: [`PublicKey`](@ref), [`PrivateKey`](@ref), [`SecureContext`](@ref),
19
[`Unencrypted`](@ref)
20
"""
21
function generate_keys(context::SecureContext{<:Unencrypted})
60✔
22
    PublicKey(context, nothing), PrivateKey(context, nothing)
60✔
23
end
24

25
"""
26
    init_multiplication!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey)
27

28
An empty duplicate of [`init_multiplication!`](@ref) for unencrypted data.
29

30
See also: [`SecureContext`](@ref), [`Unencrypted`](@ref), [`PrivateKey`](@ref),
31
[`init_multiplication!`](@ref)
32
"""
33
init_multiplication!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey) = nothing
50✔
34

35
"""
36
    init_rotation!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey,
37
                   shape, shifts...)
38

39
An empty duplicate of [`init_rotation!`](@ref) for unencrypted data.
40

41
See also: [`SecureContext`](@ref), [`Unencrypted`](@ref), [`PrivateKey`](@ref),
42
[`init_rotation!`](@ref)
43
"""
44
init_rotation!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey,
90✔
45
               shape, shifts...) = nothing
46

47
"""
48
    init_bootstrapping!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey)
49
              
50

51
An empty duplicate of [`init_bootstrapping!`](@ref) for unencrypted data.
52

53
See also: [`SecureContext`](@ref), [`Unencrypted`](@ref), [`PrivateKey`](@ref),
54
[`init_bootstrapping!`](@ref)
55
"""
56
init_bootstrapping!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey) = nothing
30✔
57

58
"""
59
    PlainVector(data::Vector{<:Real}, context::SecureContext{<:Unencrypted})
60

61
Constructor for data type [`PlainVector`](@ref) takes an unencrypted `data` vector and a `context`
62
object of type `SecureContext{<:Unencrypted}`. Returns [`PlainVector`](@ref) with not encoded and
63
not encrypted data. The context can be utilized later for encryption using [`encrypt`](@ref),
64
resulting in [`SecureVector`](@ref).
65

66
See also: [`PlainVector`](@ref), [`SecureVector`](@ref), [`encrypt`](@ref), [`decrypt`](@ref)
67
"""
68
function PlainVector(data::Vector{<:Real}, context::SecureContext{<:Unencrypted})
70✔
69
    PlainArray(data, context)
70✔
70
end
71

72
"""
73
    PlainMatrix(data::Matrix{<:Real}, context::SecureContext{<:Unencrypted})
74

75
Constructor for data type [`PlainMatrix`](@ref) takes an unencrypted `data` matrix and a `context`
76
object of type `SecureContext{<:Unencrypted}`. Returns [`PlainMatrix`](@ref) with not encoded and
77
not encrypted data. The context can be utilized later for encryption using [`encrypt`](@ref),
78
resulting in [`SecureMatrix`](@ref).
79

80
See also: [`PlainMatrix`](@ref), [`SecureMatrix`](@ref), [`encrypt`](@ref), [`decrypt`](@ref)
81
"""
82
function PlainMatrix(data::Matrix{<:Real}, context::SecureContext{<:Unencrypted})
50✔
83
    PlainArray(data, context)
50✔
84
end
85

86
"""
87
    PlainArray(data::Array{<:Real}, context::SecureContext{<:Unencrypted})
88

89
Constructor for data type [`PlainArray`](@ref) takes an unencrypted `data` array and a `context`
90
object of type `SecureContext{<:Unencrypted}`. Returns [`PlainArray`](@ref) with not encoded and
91
not encrypted data. The context can be utilized later for encryption using [`encrypt`](@ref),
92
resulting in [`SecureArray`](@ref).
93

94
See also: [`PlainArray`](@ref), [`SecureArray`](@ref), [`encrypt`](@ref), [`decrypt`](@ref)
95
"""
96
function PlainArray(data::Array{<:Real}, context::SecureContext{<:Unencrypted})
190✔
97
    PlainArray(data, size(data), length(data), context)
190✔
98
end
99

100
function Base.show(io::IO, pa::PlainArray{<:Unencrypted})
340✔
101
    print(io, pa.data)
340✔
102
end
103

104
function Base.show(io::IO, ::MIME"text/plain", pa::PlainArray{<:Unencrypted})
30✔
105
    print(io, pa.shape, "-shaped PlainArray{Unencrypted}:\n")
30✔
106
    Base.print_matrix(io, pa.data)
30✔
107
end
108

109
"""
110
    collect(pa::PlainArray{<:Unencrypted})
111

112
Return the real-valued data contained in `pa`.
113

114
See also: [`PlainArray`](@ref)
115
"""
116
function Base.collect(pa::PlainArray{<:Unencrypted})
270✔
117
    pa.data
270✔
118
end
119

120
"""
121
    level(a::Union{SecureArray{<:Unencrypted}, PlainArray{<:Unencrypted}})
122

123
Return the number of scalings, referred to as the level, performed over `a`. For data type derived
124
from `Unencrypted`, the level is always equal to 0.
125

126
See also: [`PlainArray`](@ref), [`SecureArray`](@ref)
127
"""
128
function level(a::Union{SecureArray{<:Unencrypted}, PlainArray{<:Unencrypted}})
30✔
129
    0
×
130
end
131

132
function encrypt_impl(data::Array{<:Real}, public_key::PublicKey,
30✔
133
                      context::SecureContext{<:Unencrypted})
134
    SecureArray(data, size(data), length(data), context)
30✔
135
end
136

137
function encrypt_impl(plain_array::PlainArray{<:Unencrypted}, public_key::PublicKey)
180✔
138
    SecureArray(plain_array.data, size(plain_array), capacity(plain_array),
180✔
139
                plain_array.context)
140
end
141

142
function decrypt_impl!(plain_array::PlainArray{<:Unencrypted},
480✔
143
                       secure_array::SecureArray{<:Unencrypted}, private_key::PrivateKey)
144
    plain_array.data .= secure_array.data
720✔
145

146
    plain_array
240✔
147
end
148

149
function decrypt_impl(secure_array::SecureArray{<:Unencrypted}, private_key::PrivateKey)
480✔
150
    plain_array = PlainArray(similar(secure_array.data), size(secure_array), capacity(secure_array),
720✔
151
                             secure_array.context)
152

153
    decrypt!(plain_array, secure_array, private_key)
480✔
154
end
155

156
"""
157
    bootstrap!(secure_array::SecureArray{<:Unencrypted}, num_iterations = 1,
158
               precision = 0)
159
     
160
An empty duplicate of [`bootstrap!`](@ref) for unencrypted data.
161

162
See also: [`SecureArray`](@ref), [`Unencrypted`](@ref), [`bootstrap!`](@ref),
163
[`init_bootstrapping!`](@ref)
164
"""
165
bootstrap!(secure_array::SecureArray{<:Unencrypted}, num_iterations = 1,
60✔
166
           precision = 0) = secure_array
167

168

169
############################################################################################
170
# Arithmetic operations
171
############################################################################################
172

173
function add(sa1::SecureArray{<:Unencrypted}, sa2::SecureArray{<:Unencrypted})
70✔
174
    SecureArray(sa1.data .+ sa2.data, size(sa1), capacity(sa1), sa1.context)
70✔
175
end
176

177
function add(sa::SecureArray{<:Unencrypted}, pa::PlainArray{<:Unencrypted})
60✔
178
    SecureArray(sa.data .+ pa.data, size(sa), capacity(sa), sa.context)
60✔
179
end
180

181
function add(sa::SecureArray{<:Unencrypted}, scalar::Real)
60✔
182
    SecureArray(sa.data .+ scalar, size(sa), capacity(sa), sa.context)
60✔
183
end
184

185
function subtract(sa1::SecureArray{<:Unencrypted}, sa2::SecureArray{<:Unencrypted})
60✔
186
    SecureArray(sa1.data .- sa2.data, size(sa1), capacity(sa1), sa1.context)
60✔
187
end
188

189
function subtract(sa::SecureArray{<:Unencrypted}, pa::PlainArray{<:Unencrypted})
30✔
190
    SecureArray(sa.data .- pa.data, size(sa), capacity(sa), sa.context)
30✔
191
end
192

193
function subtract(pa::PlainArray{<:Unencrypted}, sa::SecureArray{<:Unencrypted})
30✔
194
    SecureArray(pa.data .- sa.data, size(sa), capacity(sa), sa.context)
30✔
195
end
196

197
function subtract(sa::SecureArray{<:Unencrypted}, scalar::Real)
30✔
198
    SecureArray(sa.data .- scalar, size(sa), capacity(sa), sa.context)
30✔
199
end
200

201
function subtract(scalar::Real, sa::SecureArray{<:Unencrypted})
30✔
202
    SecureArray(scalar .- sa.data, size(sa), capacity(sa), sa.context)
30✔
203
end
204

205
function negate(sa::SecureArray{<:Unencrypted})
30✔
206
    SecureArray(-sa.data, size(sa), capacity(sa), sa.context)
30✔
207
end
208

209
function multiply(sa1::SecureArray{<:Unencrypted}, sa2::SecureArray{<:Unencrypted})
70✔
210
    SecureArray(sa1.data .* sa2.data, size(sa1), capacity(sa1), sa1.context)
70✔
211
end
212

213
function multiply(sa::SecureArray{<:Unencrypted}, pa::PlainArray{<:Unencrypted})
60✔
214
    SecureArray(sa.data .* pa.data, size(sa), capacity(sa), sa.context)
60✔
215
end
216

217
function multiply(sa::SecureArray{<:Unencrypted}, scalar::Real)
90✔
218
    SecureArray(sa.data .* scalar, size(sa), capacity(sa), sa.context)
90✔
219
end
220

221
function rotate(sa::SecureArray{<:Unencrypted, N}, shift) where N
270✔
222
    SecureArray(circshift(sa.data, shift), size(sa), capacity(sa), sa.context)
270✔
223
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc