
am I missing something or does scribble
not give a line number when examples
causes an error?

☞ more eg.scrbl
#lang scribble/manual
@(require scribble/examples)
@examples[(+ 1 2)]
@examples[(/ 1 0)]
@examples[(car '())]
☞ scribble --html eg.scrbl
examples: exception raised in example
error: "/: division by zero"
context...:
/Applications/Racket v7.9/share/pkgs/scribble-lib/scribble/eval.rkt:308:23: with-handlers-handler102
/Applications/Racket v7.9/collects/racket/private/more-scheme.rkt:163:2: select-handler/no-breaks
/Applications/Racket v7.9/share/pkgs/scribble-lib/scribble/eval.rkt:356:9
.../private/map.rkt:40:19: loop
body of "/Users/dvanhorn/git/cmsc430-www-sp21/www/eg.scrbl"
.../private/map.rkt:40:19: loop
.../racket/cmdline.rkt:191:51
body of "/Applications/Racket v7.9/share/pkgs/scribble-lib/scribble/run.rkt"

Is it the same in Racket BC?

that’ll take me a min to find out.

Nope, bc doesn’t have more information

I was hoping it’s https://github.com/racket/racket/issues/3645 which was recently fixed

thanks for checking

I’ll just add that DrRacket highlights the offending expression, but I’m not in a context where I can run the doc from DrRacket and it’s making it tough to track down where things broke.

DrRacket can highlight because of errortracer

If the errortracer is disabled, it cannot highlight. I don’t know if it’s possible to invoke Scribble with errortrace from command-line, though.

@dvanhorn:
racket -l errortrace -l scribble/run -- --html ~/test.scrbl

thanks!

Neat trick!

I’m trying to figure out how to choose myself a 256-bit “random number” and give it to the primitives of the package crypto-lib so that it builds me a private key for Elliptic Curve Cryptography. (I’ve managed to get keys using the libraries in the package, but I also need to use my own generated keys for tests. So I say “random number” because sometimes I need it to just be https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md\|0x35353535...35. I tried to do the reverse first: to get a private key and look inside. The procedure https://docs.racket-lang.org/crypto/pk.html?q=crypto#%28def._%28%28lib._crypto%2Fmain..rkt%29._pk-key-~3edatum%29%29\|pk-key-datum> looks very promising, but I have not found enough documentation to understand its output.) transaction.safe.rkt> (pk-key->datum privkey 'PrivateKeyInfo)
#"0\201\204\2\1\0000\20\6\a[...]\222x=,\310qq\226\265\0"
I’d expect to be able to understand the reference-document <https://tools.ietf.org/html/rfc5208|PKCS #8: Private-Key Information Syntax Specification, version 1.2>, but it does not seem to describe anything ECC-related.
More promising than that seems to be transaction.safe.rkt> (pk-key->datum privkey 'rkt-private)
'(ec
private
(1 3 132 0 10)
#"\4\226:O)$V[...]k\250"
62548863745887184901285686828072926882816647940035428474977963274923414454560)
The format is (list 'ec 'private curve-oid q x
The byte-string q
there seems to be the random number q
that is the exponent of the generator point G and x
seems to be the x-coordinate of the private key point on the curve.
Is anyone able to confirm this? (Directions on how to be confident here would be a major plus.) Thanks!

So, for instance, if this is all right, I could generate a private key from a specific random number by formating the integer as a byte string. Now would that be big-endian or little-endian? I will guess it’s little-endian on my computer — Windows 10, 64 bits. I will proceed with this assumption and see what do I get. Thanks for any information.

If q is the random number that I think it would be, it should have 32 bytes because I expect it to be a 256-bit integer. However, I find 65 bytes in the example above.

Is there a place for posix constants for errno?

You’d like to see which error messages map to which errno numbers?

Just a file with the identifiers in really; otherwise I have (define EBUSY ...)
etc.. quite a few times.

Is generate-cipher-key
of help in your case?

That looks very promising too. I wasn’t looking in ciphers, but you might be right. Also, I got a new hypothesis about the (list ’ec …) above. Maybe the byte-string is actually 65 bytes because there are two 32-byte integers separated by a space, which might be a point on the curve. So maybe x is actually the random integer that is the exponent in G^x that produces q. The number x is in fact a 256-bit integer.

I have an example for an aes-cipher: https://github.com/soegaard/web-tutorial/blob/master/listit4/app-racket-stories/secret.rkt#L26

Thank you!


That just seems to be a random-byte generator. Say (crypto-random-bytes 2) gives you two random bytes.

try lookup-errno from ffi/unsafe. E.g: > (lookup-errno ’EBUSY) 16

Maybe scribble should enable errortrace in examples by default?

Yes, as you thought above, x
is the private key’s scalar (should probably be called d
instead), and q
is the encoding of the public key’s point. The leading 04
byte means that the point is stored in “uncompressed form”, so the 04
byte is followed by two 256-bit coordinates. The right reference for EC is “SEC 1” (https://www.secg.org/sec1-v2.pdf); in particular, see section 2.3.3 about converting EC points to octet strings.

There probably should be an option in scribble
/ raco scribble
to instrument code with errortrace, but I don’t think it should be on by default. Building docs is slow already. We shouldn’t make it slower.
