Conversation
522cf4f to
17294b5
Compare
|
It seems dubious to use techniques which don't pass SB in a foundational crate like this. That means none of the users of this (perhaps transitively) can use SB. Given that SB is safer than TB (in that there are things allowed in TB which are likely to be UB eventually, which is not really true for SB), that doesn't seem good. You also don't need the |
|
@thomcc this is not nor are there plans for it to be a "foundational crate" until the soundness story is resolved. As the commit message notes, I am not rushing to use this, and the |
|
To expand on that, the main reasons I want to put this under RustCrypto:
I am happy to add an additional note about this all in the README.md, saying we aren't using it anywhere yet because of the open soundness issues. But if there are continued objections, I can just locate it under @tarcieri rather than @RustCrypto. But I thought I'd try here first. |
ba9c40b to
d420293
Compare
Adds a crate providing a `&BitSlice`/`&mut BitSlice` type which is constructable from `&[u8]` but provides slicing at the granularity of individual bits. The name of the crate is a play on `bitvec`, which provides a similar type. However, the implementation in this crate is significantly simpler with a much smaller code surface and minimal use of `unsafe` code. The implementation is a generalization of RustCrypto/formats#2300 which sought to implement a similar data structure as a reference type for representing ASN.1 BIT STRINGs. However, using this approach was deferred because the implementation relies on a conversion which is sound under Tree Borrows (as verified by Miri) but unsound under Stacked Borrows as it loses provenance. See rust-lang/unsafe-code-guidelines#134 There are several places such a data structure is potentially useful for RustCrypto projects. Beyond the previously mentioned ASN.1 BIT STRING use case, being able to iterate over bits is useful in many numerical algorithms with applications in cryptography, notably in `crypto-bigint` and for elliptic curves. Elliptic curve scalar multiplication is generally implemented as a loop over the bits of a scalar. Having an iterator type for this purpose avoids problems relating to the endianness of how scalars are serialized when implementing generic scalar multiplication algorithms, e.g. wNAF (see RustCrypto/group#12). Given the current open soundness story, I'm not rushing to use this in `crypto-bigint` until that changes. Where we could use it today though is as an optional dependency to `der`, where it can act as an ASN.1 BIT STRING type, but implement `ToOwned` producing a `der::asn1::BitString` (which, to make `ToOwned` work, needs to impl `Borrow<BitSlice>`). This would make it optionally possible to use `Cow` for copy-on-write BIT STRINGs today with `BitSlice` as the borrowed form, but leaving the preferred default data structure for that purpose as `der::asn1::BitStringRef`, which is a lifetime-parameterized struct that avoids the open soundness questions around `BitSlice`. From there we can see what develops around the soundness story and SB/TB discrepancy, and beyond that new Rust features like custom DSTs which may make expressing structures like this less of a hack.
Adds a crate providing a
&BitSlice/&mut BitSlicetype which is constructable from&[u8]but provides slicing at the granularity of individual bits. The name of the crate is a play onbitvec, which provides a similar type. However, the implementation in this crate is significantly simpler with a much smaller code surface and minimal use ofunsafecode.The implementation is a generalization of RustCrypto/formats#2300 which sought to implement a similar data structure as a reference type for representing ASN.1 BIT STRINGs. However, using this approach was deferred because the implementation relies on a conversion which is sound under Tree Borrows (as verified by Miri) but unsound under Stacked Borrows as it loses provenance. See rust-lang/unsafe-code-guidelines#134
There are several places such a data structure is potentially useful for RustCrypto projects. Beyond the previously mentioned ASN.1 BIT STRING use case, being able to iterate over bits is useful in many numerical algorithms with applications in cryptography, notably in
crypto-bigintand for elliptic curves.Elliptic curve scalar multiplication is generally implemented as a loop over the bits of a scalar. Having an iterator type for this purpose avoids problems relating to the endianness of how scalars are serialized when implementing generic scalar multiplication algorithms, e.g. wNAF (see RustCrypto/group#12).
Given the current open soundness story, I'm not rushing to use this in
crypto-bigintuntil that changes. Where we could use it today though is as an optional dependency toder, where it can act as an ASN.1 BIT STRING type, but implementToOwnedproducing ader::asn1::BitString(which, to makeToOwnedwork, needs to implBorrow<BitSlice>).This would make it optionally possible to use
Cowfor copy-on-write BIT STRINGs today withBitSliceas the borrowed form, but leaving the preferred default data structure for that purpose asder::asn1::BitStringRef, which is a lifetime-parameterized struct that avoids the open soundness questions aroundBitSlice.From there we can see what develops around the soundness story and SB/TB discrepancy, and beyond that new Rust features like custom DSTs which may make expressing structures like this less of a hack.