AEAD: Remove all use of ring::endian
and u64 from Block
.
In particular, eliminate the use of `ArrayEncoding::as_byte_array` as we work towards removing that function because it uses `unsafe`. Where `Block` is used in parameters to C/assembly code, I verified that the C/assembly code uses `uint8_t *` as the function type (meaning `uint8_t[16]`) in the BoringSSL headers. Until recently the stuff in GCM was using `uint64_t` or a union containing `uint64_t`, which is why block was previously defined in terms of `BigEndian<u64>`.
This commit is contained in:
parent
797a6eece9
commit
e6085e717f
@ -12,19 +12,18 @@
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
use crate::{endian::*, polyfill::ChunksFixed};
|
||||
use core::ops::{BitXor, BitXorAssign};
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Block([BigEndian<u64>; 2]);
|
||||
pub struct Block([u8; 16]);
|
||||
|
||||
pub const BLOCK_LEN: usize = 16;
|
||||
|
||||
impl Block {
|
||||
#[inline]
|
||||
pub fn zero() -> Self {
|
||||
Self([Encoding::ZERO; 2])
|
||||
Self([0; 16])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -45,6 +44,8 @@ impl Block {
|
||||
impl BitXorAssign for Block {
|
||||
#[inline]
|
||||
fn bitxor_assign(&mut self, a: Self) {
|
||||
// Relies heavily on optimizer to optimize this into word- or vector-
|
||||
// level XOR.
|
||||
for (r, a) in self.0.iter_mut().zip(a.0.iter()) {
|
||||
*r ^= *a;
|
||||
}
|
||||
@ -65,14 +66,13 @@ impl BitXor for Block {
|
||||
impl From<&'_ [u8; BLOCK_LEN]> for Block {
|
||||
#[inline]
|
||||
fn from(bytes: &[u8; BLOCK_LEN]) -> Self {
|
||||
let bytes: &[[u8; BLOCK_LEN / 2]; 2] = bytes.chunks_fixed();
|
||||
Self(bytes.map(Into::into))
|
||||
Self(*bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8; BLOCK_LEN]> for Block {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &[u8; BLOCK_LEN] {
|
||||
self.0.as_byte_array()
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,6 @@ macro_rules! define_endian {
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub struct $endian<T>(T);
|
||||
|
||||
impl<T> core::ops::BitXorAssign for $endian<T>
|
||||
where
|
||||
T: core::ops::BitXorAssign,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn bitxor_assign(&mut self, a: Self) {
|
||||
self.0 ^= a.0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user