SHA1Stream.st
branchjv
changeset 18027 3621469cc5e8
parent 18017 7fef9e17913f
parent 14791 4bd37b3efdb2
child 18045 c0c600e0d3b3
equal deleted inserted replaced
18026:fa8a879502cb 18027:3621469cc5e8
    98 #endif
    98 #endif
    99 {
    99 {
   100     unsigned long a, b, c, d, e;
   100     unsigned long a, b, c, d, e;
   101     typedef union {
   101     typedef union {
   102 	unsigned char c[64];
   102 	unsigned char c[64];
   103 	unsigned long l[16];
   103 	unsigned int32 /* long */ l[16];
   104     } CHAR64LONG16;
   104     } CHAR64LONG16;
   105     CHAR64LONG16* block;
   105     CHAR64LONG16* block;
   106 #ifdef SHA1HANDSOFF
   106 #ifdef SHA1HANDSOFF
   107     static unsigned char workspace[64];
   107     static unsigned char workspace[64];
   108     block = (CHAR64LONG16*)workspace;
   108     block = (CHAR64LONG16*)workspace;
   306     Generate a SHA-1 hash value as defined in
   306     Generate a SHA-1 hash value as defined in
   307     NIST, FIPS PUB 180-1: Secure Hash Standard, April 1995.
   307     NIST, FIPS PUB 180-1: Secure Hash Standard, April 1995.
   308     This may be used as checksum or for generating cryptographic signatures.
   308     This may be used as checksum or for generating cryptographic signatures.
   309 
   309 
   310     Notice (2005):
   310     Notice (2005):
   311 	Be aware that SHA-1 is considered broken and may not be appropriate in some applications.
   311         Be aware that SHA-1 is considered broken and may not be appropriate in some applications.
   312 	Especially it should no longer be used for security stuff.
   312         Especially it should no longer be used for security stuff.
   313 
   313 
   314     performance: roughly
   314     performance: roughly
   315 	   47400 Kb/s on a 2Ghz Duo
   315           120400 Kb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
   316 	    9580 Kb/s on a 400Mhz PIII
   316            47400 Kb/s on a 2Ghz Duo (old measure)
   317 	    3970 Kb/s on a 300Mhz Sparc
   317             9580 Kb/s on a 400Mhz PIII
       
   318             3970 Kb/s on a 300Mhz Sparc
   318 
   319 
   319     [author:]
   320     [author:]
   320 	Stefan Vogel
   321         Stefan Vogel
   321 
   322 
   322     [see also:]
   323     [see also:]
   323 	MD5Stream
   324         MD5Stream
   324 	SHA256Stream SHA512Stream (in libcrypt)
   325         SHA256Stream SHA512Stream (in libcrypt)
   325 
   326 
   326     [class variables:]
   327     [class variables:]
   327 	HashSize        size of returned hash value
   328         HashSize        size of returned hash value
   328 	ContextSize     (implementation) size of hash context
   329         ContextSize     (implementation) size of hash context
   329 
   330 
   330     [instance variables:]
   331     [instance variables:]
   331 	hashContext     (implementation)
   332         hashContext     (implementation)
   332 			internal buffer for computation of the hash value
   333                         internal buffer for computation of the hash value
   333 "
   334 "
   334 !
   335 !
   335 
   336 
   336 examples
   337 examples
   337 "
   338 "
   484     |digest|
   485     |digest|
   485 
   486 
   486     digest := ByteArray new:HashSize.
   487     digest := ByteArray new:HashSize.
   487 
   488 
   488 %{
   489 %{
   489     if (__isByteArray(__INST(hashContext)) &&
   490     OBJ hcon;
   490 	__byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX) &&
   491 
       
   492     hcon = __INST(hashContext);
       
   493     if (__isByteArray(hcon) &&
       
   494 	__byteArraySize(hcon) == sizeof(SHA1_CTX) &&
   491 	__isByteArray(digest) &&
   495 	__isByteArray(digest) &&
   492 	__byteArraySize(digest) == 20
   496 	__byteArraySize(digest) == 20
   493     ) {
   497     ) {
   494 	SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
   498 	SHA1_CTX *ctx = (SHA1_CTX *)(__ByteArrayInstPtr(hcon)->ba_element);
   495 	SHA1_CTX copyContext;
   499 	SHA1_CTX copyContext;
   496 
   500 
   497 	memcpy(&copyContext, ctx, sizeof(copyContext));
   501 	memcpy(&copyContext, ctx, sizeof(SHA1_CTX));
   498 	SHA1Final(__ByteArrayInstPtr(digest)->ba_element, &copyContext);
   502 	SHA1Final(__ByteArrayInstPtr(digest)->ba_element, &copyContext);
   499 	RETURN(digest);
   503 	RETURN(digest);
   500     }
   504     }
   501 %}.
   505 %}.
   502 
   506 
   576 ! !
   580 ! !
   577 
   581 
   578 !SHA1Stream class methodsFor:'documentation'!
   582 !SHA1Stream class methodsFor:'documentation'!
   579 
   583 
   580 version
   584 version
   581     ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.33 2013-01-27 13:55:22 cg Exp $'
   585     ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.36 2013-02-21 10:44:11 cg Exp $'
   582 !
   586 !
   583 
   587 
   584 version_CVS
   588 version_CVS
   585     ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.33 2013-01-27 13:55:22 cg Exp $'
   589     ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.36 2013-02-21 10:44:11 cg Exp $'
   586 ! !
   590 ! !
   587 
   591 
   588 
   592 
   589 SHA1Stream initialize!
   593 SHA1Stream initialize!