thank you Bill, things are working will post results later.
----- Original Message ----- From: bill lam <bbill....@gmail.com> To: Programming forum <programm...@jsoftware.com> Cc: Sent: Wednesday, September 2, 2015 7:51 PM Subject: Re: [Jprogramming] BigNum library from openssl I think most of your prototypes are incorrect. Since BIGNUM is opaque and you only have to deal with BIGNUM* so that you can use x for all BIGNUM*, consequently *x for BIGNUM**, also int is i in both 32 and 64-bìt. revise your prototypes and try something similar to NB. BIGNUM *BN_new(void); vbn=. ,bn=. 'libssl.so BN_new > x'&cd '' NB. int BN_dec2bn(BIGNUM **a, const char *str); rc=. 'libssl.so BN_dec2bn > i *x *c'&cd vbn;'123456789' bn=. {.vbn NB. char *BN_bn2dec(const BIGNUM *a); dec=. 'libssl.so BN_bn2dec > x x'&cd bn smoutput memr dec,0 _1 2 NB. void BN_free(BIGNUM *a); 'libssl.so BN_free > n x'&cd bn (untested) On Sep 3, 2015 3:28 AM, "'Pascal Jasmin' via Programming" < programm...@jsoftware.com> wrote: > rethreading, to address Raul's comment, the first line in old thread was > harmless and reassigned following it, but removed here. > > part of J8 is openssl libeay on windows, and I believe its either also > distributed or presumed on other platforms. It includes a BN library. As > a start, > > I need some help with the code below. after loading (windows 64 j802), > > a =. dec2bn 1231231144 NB. looks ok. > ┌──┬───────────┬──────────┐ > │10│_1181373152│1231231144│ > └──┴───────────┴──────────┘ > > |. a. i. bn2dec a > > (hopefully doesn't crash) > > I don't really know what gets returned yet, but what is worrysome is that > repeated calls return slightly different values. > > Some issues I don't know how to deal with in the code below, > > BNnum_bytes is a macro, and error 2 0 occurs if I try to call it. Is > there a workaround? > > BN_dec2bn (called above) actually has a pointer to pointer first argument > (**BIGNUM). Is there something special I have to do in the function > signature, or when calling? I'm pretending its just a pointer. > > > BN_bn2dec has a function pointer type as its declaration, and I don't know > if I need to do something special for it. > > the main doc landing page: > https://www.openssl.org/docs/manmaster/crypto/bn.html > the bn2... page > https://www.openssl.org/docs/manmaster/crypto/BN_bn2bin.html > > require 'dll' > > sslp =: IFWIN pick ''; '/',~ jpath '~bin' NB. with J802. cut this line > if you wish to point to downloaded folder > NB. OPENSSL =: jpath '~system/ssleay32.dll ' > NB.OPENSSL =: sslp , '\ssleay32.dll ' > OPENSSL =: sslp , (IFIOS + (;: 'Win Linux Android Darwin') i. <UNAME_z_) > pick 'libeay32.dll '; (2 $ <'libssl.so.1.0.0 '), (2 $ > <'/usr/lib/libssl.dylib ') > NB.OPENSSL =: sslp , (IFIOS + (;: 'Win Linux Android Darwin') i. > <UNAME_z_) pick 'libeay32.dll '; (2 $ <'libssl.so '); (2 $ > <'libssl.0.9.8.dylib ') > > SSLE =: sslp , '\openssl' > ssl =: 1 : '(OPENSSL , m)&cd' > > BNctxnew =: ' BN_CTX_new *i' ssl > BNnew =: ' BN_new *i' ssl NB. probably don't use... unamanaged memory > version. > BNmul =: ' BN_mul + l *x *x *x *x' ssl > NB. BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret) > BN2bn =: ' BN_bin2bn *x *c l *x' ssl > NB. int BN_bn2bin(const BIGNUM *a, unsigned char *to) > BN2bin =: ' BN_bn2bin l *i *c' ssl > BN_bn2hex=: ' BN_bn2bin l *i *c' ssl NB.char * BN_bn2hex(const BIGNUM *a); > BN_hex2bn =: ' BN_bn2bin l *i *c' ssl NB.(BIGNUM **a, const char *str); > BNnum_bytes=: ' BN_num_bytes i *i' ssl NB. doest work as its macro? > NB. int BN_num_bits(const BIGNUM *a) > BN_num_bits=: ' BN_num_bits i *i' ssl > num_bytes =: BN_num_bits > NB. char *BN_bn2dec(const BIGNUM *num) > BN2dec=: ' BN_bn2dec *c *i' ssl > NB. int BN_dec2bn(BIGNUM **num, const char *str) > dec2BN=: ' BN_dec2bn x *i *c' ssl > NB. BN_print(BIO *fp, const BIGNUM *a); > > > pD =: 1!:2&2 > > dec2bn=: 3 : 0 > o =. >BNnew 0{.a. > NB. o =. 0{.a. > NB.pD i=. dec2BN (o);(a. {~ 256 #. inv y) > pD i=. dec2BN (o);(": y) > 2 {. i > ) > > bn2dec=: 3 : 0 > NB.len =. BNnum_bytes y > NB.o =. len # '0' > pD y > pD o =. BN2dec (, 1 { y) > NB.pD a =.BNnum_bytes ,<o > memr (0{::o),0,(0{::y),2 > ) > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm