Thank you bill and joe and everyone for your help.
Here is code that does something, though the wikipedia test case
(http://en.wikipedia.org/wiki/Sha-2) fails, but I don't know if that is because
hfd is not the right function.
Question: when you avoid mema calls, then will the memory release itself when
the function call ends?
PROV_RSA_AES =: 24
CALG_SHA_256 =: 32780
HP_HASHVAL =: 2
CRYPT_VERIFYCONTEXT =: 4026531840
CryptAcquireContext =: ('advapi32.dll CryptAcquireContextA i *x *c *c i i') & cd
CryptReleaseContext =: 'advapi32.dll CryptReleaseContext i i i' & cd
CryptCreateHash =: 'advapi32.dll CryptCreateHash i x i i i *x' & cd
CryptDestroyHash =: 'advapi32.dll CryptDestroyHash i i' & cd
CryptHashData =: 'advapi32.dll CryptHashData i x *c i i' & cd
CryptGetHashParam =: 'advapi32.dll CryptGetHashParam i x i *c *i i' & cd
CreateHash =: 3 : 0
NB. o =. mema 32
CryptAcquireContext(aProv =. , _1);(<0);(<0);PROV_RSA_AES;CRYPT_VERIFYCONTEXT
CryptCreateHash ({. aProv) ; CALG_SHA_256 ; 0 ; 0 ; (m=. , _1)
CryptHashData ({. m) ; (y) ; (# y) ; 0
CryptGetHashParam ({. m); HP_HASHVAL ; (o2=. , 32 $ ' ' ); (,32) ; 0
NB. _3 ic memr o, 0 32
_3 ic o2
)
hfd CreateHash 'The quick brown fox jumps over the lazy dog'
9480d707b3fba8d7
4f2e08b0bc9aca69
76db3c6de451568d
92e5c937bfd0022d
hfd CreateHash 'The quick brown fox jumps over the lazy dog.'
a7bf95c8257f53ef
973db6a929655282
c289d7d5641563aa
6cfb35868c4465b7
CreateHash 'The quick brown fox jumps over the lazy dog'
_7745954930992895785 5705507333096524393 8564505559054767757
_7861656333226868179
----- Original Message -----
From: bill lam <[email protected]>
To: [email protected]
Cc:
Sent: Friday, September 6, 2013 11:44:44 AM
Subject: Re: [Jprogramming] SHA 256
I googled found that sha256 needs aes provider. I'm not sure if
that will need privilege, please try it by yourself.
[1]
http://nagareshwar.securityxploded.com/2010/10/22/cryptocode-generate-sha1sha256-hash-using-windows-cryptography-library/
Пт, 06 сен 2013, Pascal Jasmin писал(а):
> the change produces some success. It turns out I had the wrong value for
> ALGid (2nd param)
>
> I get success with passing the CALG_ID value for SHA1, but SHA256 (32780)
> seems to fail on my system
>
> CryptCreateHash ({. a2) ; 32772 ; 0 ; 0 ; (m=. , _1) NB. SHA1 hash
>
>
>
>
> ----- Original Message -----
> From: bill lam <[email protected]>
> To: [email protected]
> Cc:
> Sent: Friday, September 6, 2013 10:32:17 AM
> Subject: Re: [Jprogramming] SHA 256
>
> I guess it should be
>
> CryptCreateHash =: 'advapi32.dll CryptCreateHash i x i i i *x' & cd
> CryptCreateHash ({.a); ALG_SID_SHA_256; 0 ; 0 ; (m=.,_1)
>
> untested.
> Пт, 06 сен 2013, Joe Bogner писал(а):
> > I haven't worked out all the signatures, but I noticed that
> > CryptAcquireContext was returning zero in your version
> >
> > This version returns 1 and correctly populates a value in a
> >
> > CryptAcquireContext =: 'advapi32.dll CryptAcquireContextA i *x *c *c i i' &
> > cd
> > CryptAcquireContext (a=.,_1);(<0);(<0);PROV_RSA_FULL;CRYPT_VERIFYCONTEXT
> >
> > I haven't been able to use that context in CryptCreateHash yet
> >
> > I was thinking that I could do this:
> >
> > CryptCreateHash =: 'advapi32.dll CryptCreateHash i *x i i i *x' & cd
> > CryptCreateHash a; ALG_SID_SHA_256; 0 ; 0 ; (m=.,_1)
> >
> > Yet that's returning 0 and m is _1
> >
> >
> >
> >
> > On Fri, Sep 6, 2013 at 7:31 AM, Henry Rich <[email protected]> wrote:
> >
> > > On rereading, I think I am wrong here. Ignore this.
> > >
> > > Henry Rich
> > >
> > >
> > > On 9/6/2013 5:22 AM, Henry Rich wrote:
> > >
> > >> I'm looking at
> > >>
> > >> CryptCreateHash =: 'advapi32.dll CryptCreateHash i *i i i i *i' & cd
> > >> err =. CryptCreateHash (<a); ALG_SID_SHA_256 ; 0 ; 0 ; (<<h)
> > >>
> > >> and I don't understand why this doesn't give an error on parameters a
> > >> and h. They correspond to *i descriptors, but they are scalar boxes. I
> > >> thought they needed to be scalars, so I would use
> > >>
> > >> err =. CryptCreateHash a; ALG_SID_SHA_256 ; 0 ; 0 ; h
> > >>
> > >> Similar cases later on
> > >>
> > >>
> > >> Untested.
> > >>
> > >> Henry Rich
> > >>
> > >> On 9/6/2013 12:10 AM, Pascal Jasmin wrote:
> > >>
> > >>> I'm trying to get sha256 from microsoft's library working.
> > >>>
> > >>> MS documentation on the last call in my function:
> > >>> http://msdn.microsoft.com/en-**us/library/windows/desktop/**
> > >>> aa379947(v=vs.85).aspx<http://msdn.microsoft.com/en-us/library/windows/desktop/aa379947(v=vs.85).aspx>
> > >>>
> > >>>
> > >>> The problem is that the 3rd param to CryptGetHashParam is a pointer to
> > >>> a byte array, and should hold the hash result, but I'm unable to see
> > >>> it change. The 2nd param in CryptHashData may also be called
> > >>> incorrectly here.
> > >>>
> > >>> any help?
> > >>>
> > >>>
> > >>> ALG_SID_SHA_256 =: 12
> > >>> ALG_CLASS_HASH =: 32768
> > >>> PROV_RSA_FULL =:1
> > >>> PROV_RSA_AES =: 24
> > >>> HP_HASHVAL =: 2
> > >>> CRYPT_VERIFYCONTEXT =: 4026531840
> > >>> CryptAcquireContext =: ('advapi32.dll CryptAcquireContextA i *i c c i
> > >>> i') & cd
> > >>> NB.(ByRef phProv As Long, ByVal pszContainer As String, ByVal
> > >>> pszProvider As String, ByVal dwProvType As Long, ByVal dwFlags As Long)
> > >>> CryptReleaseContext =: 'advapi32.dll CryptReleaseContext i i i' & cd
> > >>> NB. (ByVal hProv As Long, ByVal dwFlags As Long) As Long
> > >>> CryptCreateHash =: 'advapi32.dll CryptCreateHash i *i i i i *i' & cd
> > >>> NB.(ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long,
> > >>> ByVal dwFlags As Long, ByRef phHash As Long) As Long
> > >>> CryptDestroyHash =: 'advapi32.dll CryptDestroyHash i i' & cd
> > >>> NB.(ByVal hHash As Long) As Long
> > >>> CryptHashData =: 'advapi32.dll CryptHashData i *i *c i i' & cd
> > >>> NB.(ByVal hHash As Long, pbData As Any, ByVal cbData As Long, ByVal
> > >>> dwFlags As Long) As Long
> > >>> CryptGetHashParam =: 'advapi32.dll CryptGetHashParam i *i i *c *i i' &
> > >>> cd
> > >>> NB.(ByVal hHash As Long, ByVal dwParam As Long, pbData As Any, ByRef
> > >>> pcbData As Long, ByVal dwFlags As Long) As Long
> > >>>
> > >>>
> > >>>
> > >>> CreateHash =: 3 : 0
> > >>> a =. mema 8
> > >>> h =. mema 128
> > >>> o =. mema 32
> > >>>
> > >>> err=. CryptAcquireContext (<a);' ';' ';PROV_RSA_FULL;CRYPT_**
> > >>> VERIFYCONTEXT
> > >>> err =. CryptCreateHash (<a); ALG_SID_SHA_256 ; 0 ; 0 ; (<<h)
> > >>> y memw o, 0 , # y
> > >>> CryptHashData (<h) ; (y) ; (# y) ; 0
> > >>> CryptGetHashParam (<h); HP_HASHVAL ; (<o ); (,32) ; 0
> > >>> NB. memr o, 0, # y
> > >>> )
> > >>>
> > >>>
> > >>> vb code that i adapted this from:
> > >>> http://khoiriyyah.blogspot.ca/**2012/06/vb6-hash-class-md5-**
> > >>> sha-1-sha-256-sha.html<http://khoiriyyah.blogspot.ca/2012/06/vb6-hash-class-md5-sha-1-sha-256-sha.html>
> > >>>
> > >>> ------------------------------**------------------------------**
> > >>> ----------
> > >>> For information about J forums see
> > >>> http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
> > >>>
> > >>> ------------------------------**------------------------------**
> > >> ----------
> > >> For information about J forums see
> > >> http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
> > >>
> > >> ------------------------------**------------------------------**
> > > ----------
> > > For information about J forums see
> > > http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
> > >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm