New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
der: support for the REAL
type
#304
Comments
I am not familiar with a DER encoding of ASN.1 REAL. DER encodings are intended for cryptographic applications and MUST be canonical. Canonicalizing You likely want BER instead, which this crate purposefully does not support so as to stay laser-focused on DER. |
Interesting. What is the reference you're using for DER so I can make sure to adhere to that? For those who need this, one can rebuild the floating type as per the specs using the following ASN.1 definition, which looks canonical to me, but maybe I'm missing something:
The following works for the encoding of Pi:
This works in the playground and is oddly slightly more efficient in the encoding of a Real than the default implementation of the playground. |
DER is defined in ITU X.690 |
Okay, sorry I guess I missed that. If you'd like it implemented you'll have to contribute the implementation yourself. Our use cases are all cryptography, and given that floating point support is very much outside our purview. |
Hi. Could you give me some tips on how I would go about starting the implementation of that type? Thanks |
You can look at the other ASN.1 type definitions here for examples: https://github.com/RustCrypto/formats/tree/master/der/src/asn1 You’ll need to implement the same set of traits as the types in those modules. |
Hi there, I've started the decoding implementation and had a design question I was hoping you could provide some guidance on. As per the specs of the exponent encoding (below), it seems to me that the exponent can be encoded on several octets/bytes. However, the IEEE 754 standard (as implement in Rust as f64) only supports 11 bits of exponent. Question: how would you prefer this to be designed?
Looking forward to reading your advice, thanks. |
You should be able to construct a |
How do you understand section 8.5.8? The ISO 6093 NR3 format seems to me like a string representation of a floating point value (cf. page 7 of this PDF). I would be immensely surprised if that's what ASN.1 had in mind for a base 10 encoding given how optimized the base 2 encoding is. Further, from section 2.4 of this PDF, the general idea of ASN.1 real encoding is to encode the value on three integers Thanks for your help |
There's some discussion of the BER encoding here: https://stackoverflow.com/questions/4975005/how-should-i-interpret-the-asn-1-ber-standard-for-reals It indeed does appear to be a string encoding. That's not too far off from the encoding of types like It appears that
|
Two questions:
Thanks |
Re 1) I suppose it's OK although I'm not sure how or why you'd need Re 2) |
|
There's already a https://github.com/RustCrypto/formats/blob/master/der/src/str_slice.rs |
Just open the merge request #346 . I tried to squash my commits but it seems like that failed, sorry. As mentioned in the description, I'd like a hand to make sure I interpret section 11.3.1 correctly. From what I understand, the implementation should ensure that the mantissa is chosen such that it is zero (not just an even number) or and odd number by shifting the mantissa values to the right (dividing by two) and increasing the exponent by that same number. But how does that make sense? The exponent value is directly tied to the mantissa, and, unless I'm mistaken, there truly is only one way to arrange the bit in an IEEE-754 to make a given value. In fact, a quick demo in the playground seems to show that as well. What am I misunderstanding in this section (below for reference)? Thanks for your continued help. EditI might have understood the idea: if the mantissa is neither zero nor is odd, then shift the mantissa by 1 and store that shift, not in the exponent, but in the The diff is simply the following:
That said, I don't quite understand the benefit of this method: it still requires just as much room to store the double as before. Specs |
@tarcieri hi Tony, I was wondering if there was anything I could do to help review and merge this work? It seems like the ASN1CC compiler might support the |
Hi there,
I'm seriously considering using your library to encode lots of
f64
data (cf. https://github.com/anise-toolkit , and specifically this flatbuffer example: https://github.com/anise-toolkit/specs/blob/1-draft-0-0-1/ephemeris.fbs ).I'm brand new to ASN.1, so please excuse novice questions. According to a copy of some specs I found here, https://www.oss.com/asn1/resources/books-whitepapers-pubs/larmouth-asn1-book.pdf, section 2.4 (page 83) talks about a
REAL
type. The ASN.1 playground also uses that type in their default example: https://asn1.io/asn1playground/ .However, I don't see it in the docs as one of the supported type (https://docs.rs/der/latest/der/asn1/index.html).
Is the REAL type not supported in DER encoding? Or has it not yet been implemented in this library because it isn't needed for the crypto algorithms?
Thanks
The text was updated successfully, but these errors were encountered: