<feed xmlns='http://www.w3.org/2005/Atom'>
<title>openbsd/src/lib/libcrypto/bn, branch OPENBSD_7_3_BASE</title>
<subtitle>A mirror of https://github.com/libressl/openbsd.git
</subtitle>
<id>https://git.lua4.win/openbsd/atom?h=OPENBSD_7_3_BASE</id>
<link rel='self' href='https://git.lua4.win/openbsd/atom?h=OPENBSD_7_3_BASE'/>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/'/>
<updated>2023-03-15T04:30:20+00:00</updated>
<entry>
<title>Ensure negative input to BN_mod_exp_mont_consttime() is correctly reduced.</title>
<updated>2023-03-15T04:30:20+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-15T04:30:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=d3cf2a2533c22b330e12679aad10a700eb6fc870'/>
<id>urn:sha1:d3cf2a2533c22b330e12679aad10a700eb6fc870</id>
<content type='text'>
A negative input to BN_mod_exp_mont_consttime() is not correctly reduced,
remaining negative (when it should be in the range [0, m)). Fix this by
unconditionally calling BN_nnmod() on the input.

Fixes ossfuzz #55997.

ok tb@
</content>
</entry>
<entry>
<title>Avoid -0 in BN_div_word().</title>
<updated>2023-03-11T14:14:54+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-11T14:14:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=52fd1244f8c53de73ef10d4f9511eee80489d31a'/>
<id>urn:sha1:52fd1244f8c53de73ef10d4f9511eee80489d31a</id>
<content type='text'>
Currently, the use of BN_div_word() can result in -0 - avoid this by
setting negative again, at the end of the computation.

Should fix oss-fuzz 56667.

ok tb@
</content>
</entry>
<entry>
<title>Correct sign handling in BN_add_word().</title>
<updated>2023-03-11T14:13:11+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-11T14:13:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=0011bd4b5ca21dd631b72942920a62fa4a90fa88'/>
<id>urn:sha1:0011bd4b5ca21dd631b72942920a62fa4a90fa88</id>
<content type='text'>
A sign handling bug was introduced to BN_add_word() in bn_word.c r1.18.
When handling addition to a negative bignum, the BN_sub_word() call can
result in the sign being flipped, which we need to account for. Use the
same code in BN_sub_word() - while not technically needed here it keeps
the code consistent.

Issue discovered by tb@

ok tb@
</content>
</entry>
<entry>
<title>Improve bn_montgomery_multiply_words().</title>
<updated>2023-03-07T09:42:09+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T09:42:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=ecd1f4763943bcfd15caa4b48ac41a4b1f90be7a'/>
<id>urn:sha1:ecd1f4763943bcfd15caa4b48ac41a4b1f90be7a</id>
<content type='text'>
Rather than calling bn_mul_add_words() twice - once to multiply and once
to reduce - perform the multiplication and reduction in a single pass using
bn_mulw_addw_addw() directly. Also simplify the addition of the resulting
carries, which in turn allows us to avoid zeroing the top half of the
temporary words.

This provides a ~20-25% performance improvement for RSA operations on
aarch64.

ok tb@
</content>
</entry>
<entry>
<title>Slightly rework bn_mulw_addtw().</title>
<updated>2023-03-07T09:35:55+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T09:35:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=2797564eff6fe818c2b46b64fbb198f80be86e35'/>
<id>urn:sha1:2797564eff6fe818c2b46b64fbb198f80be86e35</id>
<content type='text'>
Call bn_mulw_addw() rather than doing bn_mulw() follow by bn_addw(). This
simplifies the code slightly, plus on some platforms bn_mulw_addw() can
be optimised (and bn_mulw_addtw() will then benefit from such an
optimisation).

ok tb@
</content>
</entry>
<entry>
<title>Call BN_free() instead of BN_clear_free().</title>
<updated>2023-03-07T09:27:10+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T09:27:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=19dfe7f484e5739359ee8c102d879d125df916ad'/>
<id>urn:sha1:19dfe7f484e5739359ee8c102d879d125df916ad</id>
<content type='text'>
BN_clear_free() is a wrapper that calls BN_free() - call BN_free() directly
instead.

ok tb@
</content>
</entry>
<entry>
<title>Limit bn_mul_mont() usage to sizes less than or equal to 8192 bits.</title>
<updated>2023-03-07T06:28:36+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T06:28:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=9a319239aa9791b8d59bd245ae1eb82cd3d46720'/>
<id>urn:sha1:9a319239aa9791b8d59bd245ae1eb82cd3d46720</id>
<content type='text'>
The assembly bn_mul_mont() implementations effectively use alloca() to
allocate space for computation (at up to 8x the input size), without
any limitation. This means that sufficiently large inputs lead to the
stack being blown. Prevent this by using the C based implementation
instead.

Thanks to Jiayi Lin &lt;jlin139 at asu dot edu&gt; for reporting this to us.

ok beck@ tb@
</content>
</entry>
<entry>
<title>Implement bn_montgomery_multiply()</title>
<updated>2023-03-07T06:19:44+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T06:19:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=0997c0b71b5d3563776da385640073eeb53919be'/>
<id>urn:sha1:0997c0b71b5d3563776da385640073eeb53919be</id>
<content type='text'>
Provide a constant-time-style Montgomery multiplication implementation.
Use this in place of the assembly bn_mul_mont() on platforms that either
do not have an assembly implementation or have not compiled it in.

Also use this as the fallback version for bn_mul_mont(), rather than
falling back to a non-constant time implementation.

ok beck@ tb@
</content>
</entry>
<entry>
<title>Refactor BN_mod_mul_montgomery().</title>
<updated>2023-03-07T06:15:09+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T06:15:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=9b37857f5b8c81178521129dbb3c0afdcab594ac'/>
<id>urn:sha1:9b37857f5b8c81178521129dbb3c0afdcab594ac</id>
<content type='text'>
Pull out the simplistic implementation (using BN_mul() or BN_sqr()) into a
bn_mod_mul_montgomery_simple() function. Provide bn_mod_mul_montgomery()
with an implementation that changes depending on if the assembly
bn_mul_mont() is available or not. Turn BN_mod_mul_montgomery() and
BN_to_montgomery() into callers of bn_mod_mul_montgomery().

ok beck@ tb@
</content>
</entry>
<entry>
<title>Delete unused and unsafe bn_mul_mont() example code.</title>
<updated>2023-03-07T06:05:06+00:00</updated>
<author>
<name>jsing</name>
<email></email>
</author>
<published>2023-03-07T06:05:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.lua4.win/openbsd/commit/?id=a11e3f4bc655f7f0e41fc25cdf9ae62072074f19'/>
<id>urn:sha1:a11e3f4bc655f7f0e41fc25cdf9ae62072074f19</id>
<content type='text'>
This came from bn_asm.c and did not even compile until recently.

ok beck@ tb@
</content>
</entry>
</feed>
