Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs

This commit is contained in:
2026-09-15 10:41:00 -06:00
parent 6dc77e8eb0
commit a2b65bb47f
16427 changed files with 6972976 additions and 3 deletions
+204
View File
@@ -0,0 +1,204 @@
use super::{
AlgorithmName, Buffer, BufferKindUser, FixedOutputCore, Reset, TruncSide, UpdateCore,
VariableOutputCore,
};
use crate::HashMarker;
#[cfg(feature = "mac")]
use crate::MacMarker;
#[cfg(feature = "oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
use core::{fmt, marker::PhantomData};
use crypto_common::{
generic_array::{ArrayLength, GenericArray},
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, U256},
Block, BlockSizeUser, OutputSizeUser,
};
/// Dummy type used with [`CtVariableCoreWrapper`] in cases when
/// resulting hash does not have a known OID.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct NoOid;
/// Wrapper around [`VariableOutputCore`] which selects output size
/// at compile time.
#[derive(Clone)]
pub struct CtVariableCoreWrapper<T, OutSize, O = NoOid>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
inner: T,
_out: PhantomData<(OutSize, O)>,
}
impl<T, OutSize, O> HashMarker for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore + HashMarker,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
#[cfg(feature = "mac")]
impl<T, OutSize, O> MacMarker for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore + MacMarker,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
impl<T, OutSize, O> BlockSizeUser for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type BlockSize = T::BlockSize;
}
impl<T, OutSize, O> UpdateCore for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
self.inner.update_blocks(blocks);
}
}
impl<T, OutSize, O> OutputSizeUser for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize> + 'static,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type OutputSize = OutSize;
}
impl<T, OutSize, O> BufferKindUser for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type BufferKind = T::BufferKind;
}
impl<T, OutSize, O> FixedOutputCore for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize> + 'static,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn finalize_fixed_core(
&mut self,
buffer: &mut Buffer<Self>,
out: &mut GenericArray<u8, Self::OutputSize>,
) {
let mut full_res = Default::default();
self.inner.finalize_variable_core(buffer, &mut full_res);
let n = out.len();
let m = full_res.len() - n;
match T::TRUNC_SIDE {
TruncSide::Left => out.copy_from_slice(&full_res[..n]),
TruncSide::Right => out.copy_from_slice(&full_res[m..]),
}
}
}
impl<T, OutSize, O> Default for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn default() -> Self {
Self {
inner: T::new(OutSize::USIZE).unwrap(),
_out: PhantomData,
}
}
}
impl<T, OutSize, O> Reset for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn reset(&mut self) {
*self = Default::default();
}
}
impl<T, OutSize, O> AlgorithmName for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore + AlgorithmName,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
T::write_alg_name(f)?;
f.write_str("_")?;
write!(f, "{}", OutSize::USIZE)
}
}
#[cfg(feature = "oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))]
impl<T, OutSize, O> AssociatedOid for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
O: AssociatedOid,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const OID: ObjectIdentifier = O::OID;
}
/// Implement dummy type with hidden docs which is used to "carry" hasher
/// OID for [`CtVariableCoreWrapper`].
#[macro_export]
macro_rules! impl_oid_carrier {
($name:ident, $oid:literal) => {
#[doc(hidden)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct $name;
#[cfg(feature = "oid")]
impl AssociatedOid for $name {
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid);
}
};
}
+166
View File
@@ -0,0 +1,166 @@
use super::{AlgorithmName, TruncSide, UpdateCore, VariableOutputCore};
#[cfg(feature = "mac")]
use crate::MacMarker;
use crate::{HashMarker, InvalidBufferSize};
use crate::{InvalidOutputSize, Reset, Update, VariableOutput, VariableOutputReset};
use block_buffer::BlockBuffer;
use core::fmt;
use crypto_common::typenum::{IsLess, Le, NonZero, Unsigned, U256};
/// Wrapper around [`VariableOutputCore`] which selects output size
/// at run time.
#[derive(Clone)]
pub struct RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
core: T,
buffer: BlockBuffer<T::BlockSize, T::BufferKind>,
output_size: usize,
}
impl<T> RtVariableCoreWrapper<T>
where
T: VariableOutputCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn finalize_dirty(&mut self, out: &mut [u8]) -> Result<(), InvalidBufferSize> {
let Self {
core,
buffer,
output_size,
} = self;
if out.len() != *output_size || out.len() > Self::MAX_OUTPUT_SIZE {
return Err(InvalidBufferSize);
}
let mut full_res = Default::default();
core.finalize_variable_core(buffer, &mut full_res);
let n = out.len();
let m = full_res.len() - n;
match T::TRUNC_SIDE {
TruncSide::Left => out.copy_from_slice(&full_res[..n]),
TruncSide::Right => out.copy_from_slice(&full_res[m..]),
}
Ok(())
}
}
impl<T> HashMarker for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + HashMarker,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
#[cfg(feature = "mac")]
#[cfg_attr(docsrs, doc(cfg(feature = "mac")))]
impl<T> MacMarker for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + MacMarker,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
impl<T> Reset for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore + Reset,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn reset(&mut self) {
self.buffer.reset();
self.core.reset();
}
}
impl<T> Update for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn update(&mut self, input: &[u8]) {
let Self { core, buffer, .. } = self;
buffer.digest_blocks(input, |blocks| core.update_blocks(blocks));
}
}
impl<T> VariableOutput for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const MAX_OUTPUT_SIZE: usize = T::OutputSize::USIZE;
fn new(output_size: usize) -> Result<Self, InvalidOutputSize> {
let buffer = Default::default();
T::new(output_size).map(|core| Self {
core,
buffer,
output_size,
})
}
fn output_size(&self) -> usize {
self.output_size
}
fn finalize_variable(mut self, out: &mut [u8]) -> Result<(), InvalidBufferSize> {
self.finalize_dirty(out)
}
}
impl<T> VariableOutputReset for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore + Reset,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
fn finalize_variable_reset(&mut self, out: &mut [u8]) -> Result<(), InvalidBufferSize> {
self.finalize_dirty(out)?;
self.core.reset();
self.buffer.reset();
Ok(())
}
}
impl<T> fmt::Debug for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore + AlgorithmName,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
T::write_alg_name(f)?;
f.write_str(" { .. }")
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> std::io::Write for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Update::update(self, buf);
Ok(buf.len())
}
#[inline]
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
+290
View File
@@ -0,0 +1,290 @@
use super::{
AlgorithmName, Buffer, BufferKindUser, ExtendableOutputCore, FixedOutputCore, OutputSizeUser,
Reset, UpdateCore, XofReaderCoreWrapper,
};
use crate::{
ExtendableOutput, ExtendableOutputReset, FixedOutput, FixedOutputReset, HashMarker, Update,
};
use block_buffer::BlockBuffer;
use core::fmt;
use crypto_common::{
typenum::{IsLess, Le, NonZero, U256},
BlockSizeUser, InvalidLength, Key, KeyInit, KeySizeUser, Output,
};
#[cfg(feature = "mac")]
use crate::MacMarker;
#[cfg(feature = "oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
/// Wrapper around [`BufferKindUser`].
///
/// It handles data buffering and implements the slice-based traits.
#[derive(Clone, Default)]
pub struct CoreWrapper<T>
where
T: BufferKindUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
core: T,
buffer: BlockBuffer<T::BlockSize, T::BufferKind>,
}
impl<T> HashMarker for CoreWrapper<T>
where
T: BufferKindUser + HashMarker,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
#[cfg(feature = "mac")]
#[cfg_attr(docsrs, doc(cfg(feature = "mac")))]
impl<T> MacMarker for CoreWrapper<T>
where
T: BufferKindUser + MacMarker,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
// this blanket impl is needed for HMAC
impl<T> BlockSizeUser for CoreWrapper<T>
where
T: BufferKindUser + HashMarker,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type BlockSize = T::BlockSize;
}
impl<T> CoreWrapper<T>
where
T: BufferKindUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
/// Create new wrapper from `core`.
#[inline]
pub fn from_core(core: T) -> Self {
let buffer = Default::default();
Self { core, buffer }
}
/// Decompose wrapper into inner parts.
#[inline]
pub fn decompose(self) -> (T, Buffer<T>) {
let Self { core, buffer } = self;
(core, buffer)
}
}
impl<T> KeySizeUser for CoreWrapper<T>
where
T: BufferKindUser + KeySizeUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type KeySize = T::KeySize;
}
impl<T> KeyInit for CoreWrapper<T>
where
T: BufferKindUser + KeyInit,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn new(key: &Key<Self>) -> Self {
Self {
core: T::new(key),
buffer: Default::default(),
}
}
#[inline]
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
Ok(Self {
core: T::new_from_slice(key)?,
buffer: Default::default(),
})
}
}
impl<T> fmt::Debug for CoreWrapper<T>
where
T: BufferKindUser + AlgorithmName,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
T::write_alg_name(f)?;
f.write_str(" { .. }")
}
}
impl<T> Reset for CoreWrapper<T>
where
T: BufferKindUser + Reset,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn reset(&mut self) {
self.core.reset();
self.buffer.reset();
}
}
impl<T> Update for CoreWrapper<T>
where
T: BufferKindUser + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn update(&mut self, input: &[u8]) {
let Self { core, buffer } = self;
buffer.digest_blocks(input, |blocks| core.update_blocks(blocks));
}
}
impl<T> OutputSizeUser for CoreWrapper<T>
where
T: BufferKindUser + OutputSizeUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type OutputSize = T::OutputSize;
}
impl<T> FixedOutput for CoreWrapper<T>
where
T: FixedOutputCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn finalize_into(mut self, out: &mut Output<Self>) {
let Self { core, buffer } = &mut self;
core.finalize_fixed_core(buffer, out);
}
}
impl<T> FixedOutputReset for CoreWrapper<T>
where
T: FixedOutputCore + Reset,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn finalize_into_reset(&mut self, out: &mut Output<Self>) {
let Self { core, buffer } = self;
core.finalize_fixed_core(buffer, out);
core.reset();
buffer.reset();
}
}
impl<T> ExtendableOutput for CoreWrapper<T>
where
T: ExtendableOutputCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
<T::ReaderCore as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<T::ReaderCore as BlockSizeUser>::BlockSize, U256>: NonZero,
{
type Reader = XofReaderCoreWrapper<T::ReaderCore>;
#[inline]
fn finalize_xof(self) -> Self::Reader {
let (mut core, mut buffer) = self.decompose();
let core = core.finalize_xof_core(&mut buffer);
let buffer = Default::default();
Self::Reader { core, buffer }
}
}
impl<T> ExtendableOutputReset for CoreWrapper<T>
where
T: ExtendableOutputCore + Reset,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
<T::ReaderCore as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<T::ReaderCore as BlockSizeUser>::BlockSize, U256>: NonZero,
{
#[inline]
fn finalize_xof_reset(&mut self) -> Self::Reader {
let Self { core, buffer } = self;
let reader_core = core.finalize_xof_core(buffer);
core.reset();
buffer.reset();
let buffer = Default::default();
Self::Reader {
core: reader_core,
buffer,
}
}
}
#[cfg(feature = "oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))]
impl<T> AssociatedOid for CoreWrapper<T>
where
T: BufferKindUser + AssociatedOid,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const OID: ObjectIdentifier = T::OID;
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> std::io::Write for CoreWrapper<T>
where
T: BufferKindUser + UpdateCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Update::update(self, buf);
Ok(buf.len())
}
#[inline]
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
/// A proxy trait to a core type implemented by [`CoreWrapper`]
// TODO: replace with an inherent associated type on stabilization:
// https://github.com/rust-lang/rust/issues/8995
pub trait CoreProxy: sealed::Sealed {
/// Type wrapped by [`CoreWrapper`].
type Core;
}
mod sealed {
pub trait Sealed {}
}
impl<T> sealed::Sealed for CoreWrapper<T>
where
T: BufferKindUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
}
impl<T> CoreProxy for CoreWrapper<T>
where
T: BufferKindUser,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
type Core = T;
}
+63
View File
@@ -0,0 +1,63 @@
use super::{AlgorithmName, XofReaderCore};
use crate::XofReader;
use block_buffer::EagerBuffer;
use core::fmt;
use crypto_common::typenum::{IsLess, Le, NonZero, U256};
/// Wrapper around [`XofReaderCore`] implementations.
///
/// It handles data buffering and implements the mid-level traits.
#[derive(Clone, Default)]
pub struct XofReaderCoreWrapper<T>
where
T: XofReaderCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
pub(super) core: T,
pub(super) buffer: EagerBuffer<T::BlockSize>,
}
impl<T> fmt::Debug for XofReaderCoreWrapper<T>
where
T: XofReaderCore + AlgorithmName,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
T::write_alg_name(f)?;
f.write_str(" { .. }")
}
}
impl<T> XofReader for XofReaderCoreWrapper<T>
where
T: XofReaderCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn read(&mut self, buffer: &mut [u8]) {
let Self { core, buffer: buf } = self;
buf.set_data(buffer, |blocks| {
for block in blocks {
*block = core.read_block();
}
});
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> std::io::Read for XofReaderCoreWrapper<T>
where
T: XofReaderCore,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
#[inline]
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
XofReader::read(self, buf);
Ok(buf.len())
}
}