dvanhorn
2021-1-23 17:07:50

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


dvanhorn
2021-1-23 17:08:07

☞ 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"


sorawee
2021-1-23 17:08:48

Is it the same in Racket BC?


dvanhorn
2021-1-23 17:09:34

that’ll take me a min to find out.


sorawee
2021-1-23 17:11:14

Nope, bc doesn’t have more information


sorawee
2021-1-23 17:11:29

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


dvanhorn
2021-1-23 17:12:11

thanks for checking


dvanhorn
2021-1-23 17:14:32

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.


sorawee
2021-1-23 17:16:50

DrRacket can highlight because of errortracer


sorawee
2021-1-23 17:18:44

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.


sorawee
2021-1-23 17:33:17

@dvanhorn:

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


dvanhorn
2021-1-23 17:33:31

thanks!


soegaard2
2021-1-23 17:38:50

Neat trick!


anything
2021-1-23 18:58:22

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&gt; (pk-key-&gt;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&gt; (pk-key-&gt;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!


anything
2021-1-23 19:01:25

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.


anything
2021-1-23 19:03:33

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.


yilin.wei10
2021-1-23 19:04:35

Is there a place for posix constants for errno?


anything
2021-1-23 19:08:21

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


yilin.wei10
2021-1-23 19:11:06

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


soegaard2
2021-1-23 19:13:57

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


anything
2021-1-23 19:16:49

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.


soegaard2
2021-1-23 19:18:01

anything
2021-1-23 19:20:37

Thank you!



anything
2021-1-23 19:22:18

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


capfredf
2021-1-23 20:13:16

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


notjack
2021-1-23 22:55:59

Maybe scribble should enable errortrace in examples by default?


ryanc
2021-1-24 00:21:21

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.


sorawee
2021-1-24 05:21:15

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.