SHA1Stream.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23959 5e284faa1acc
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22563
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
     1
"{ Encoding: utf8 }"
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
     2
4426
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
     3
"
15038
22f613e86520 class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15025
diff changeset
     4
 COPYRIGHT (c) 1999-2013 by eXept Software AG
15907
b6a05f7d463f use int32 instead of long (for 64bit machines)
Claus Gittinger <cg@exept.de>
parents: 15623
diff changeset
     5
	      All Rights Reserved
4426
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
     6
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
     7
 This software is furnished under a license and may be used
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
     8
 only in accordance with the terms of that license and with the
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
    10
 be provided or otherwise made available to, or used by, any
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
    11
 other person.  No title to or ownership of the software is
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
    12
 hereby transferred.
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
    13
"
9369
b7f43a51c4ed Moved SHA1Stream from exept:libcrypt to stx:libbasic
Stefan Vogel <sv@exept.de>
parents: 7824
diff changeset
    14
"{ Package: 'stx:libbasic' }"
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
19160
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
    16
"{ NameSpace: Smalltalk }"
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
    17
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
HashStream subclass:#SHA1Stream
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'hashContext'
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
	classVariableNames:'HashSize ContextSize'
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
12420
a422d9a78479 category changes
Claus Gittinger <cg@exept.de>
parents: 12265
diff changeset
    22
	category:'System-Crypt-Hashing'
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    25
!SHA1Stream primitiveDefinitions!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
%{
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    27
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
    28
#if defined(__LSBFIRST) || defined(__LSBFIRST__)
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    29
# ifndef LITTLE_ENDIAN
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    30
#  define LITTLE_ENDIAN /* This should be #define'd if true. */
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    31
# endif
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    32
#endif
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    33
5056
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
    34
#define SHA1HANDSOFF /* Copies data before messing with it. */
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    35
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    36
#ifndef _STDIO_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    37
# include <stdio.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    38
# define _STDIO_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    39
#endif
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    40
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    41
#ifndef _STRING_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    42
# include <string.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    43
# define _STRING_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 21152
diff changeset
    44
#endif
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
typedef struct {
15025
552103f2ae6e 64bit (mac) fix: long is not an int32 here
Claus Gittinger <cg@exept.de>
parents: 14791
diff changeset
    47
    unsigned int32 state[5];
552103f2ae6e 64bit (mac) fix: long is not an int32 here
Claus Gittinger <cg@exept.de>
parents: 14791
diff changeset
    48
    unsigned int32 count[2];
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    49
    unsigned char buffer[64];
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
} SHA1_CTX;
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
23958
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    52
#if (defined(__GNUC__) || defined(__CLANG__))
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    53
# define STATIC_INLINE static inline
23959
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    54
#else
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    55
# define STATIC_INLINE static
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    56
#endif
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    57
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    58
#if (defined(__GNUC__) || defined(__CLANG__))
23958
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    59
# if (defined(__SSE4_1__) && defined(__SHA__))
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    60
#  if __SSE4_1__ && __SHA__
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    61
// # define __SSE4_1__ 1
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    62
// # define __SHA__    1
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    63
#   include <immintrin.h>
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    64
 static void SHA1Transform(unsigned int32 state[5], unsigned char buffer[64]);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    65
 // static void __attribute__ ((__target__ ("sha,sse4.1"))) SHA1Transform_x86(unsigned int32 state[5], unsigned char buffer[64]);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    66
 static void SHA1Transform_x86(unsigned int32 state[5], unsigned char buffer[64]);
23958
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    67
#   define USE_SHA_INTRINSICS
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    68
#  endif
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
    69
# endif
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    70
#endif
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    71
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    72
#ifndef USE_SHA_INTRINSICS
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    73
# define SHA1Transform SHA1Transform_generic
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    74
#endif
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    75
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    76
#if USE_ANSI_C
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    77
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
    78
 static void SHA1Transform_generic(unsigned int32 state[5], unsigned char buffer[64]);
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    79
 STATIC_INLINE void SHA1Init(SHA1_CTX* context);
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    80
 void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len);
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    81
 void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    82
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    83
#else /* general: compiles everywhere */
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    84
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    85
# define SHA1Init   __SHA1Init
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    86
# define SHA1Update __SHA1Update
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    87
# define SHA1Final  __SHA2Final
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
23959
5e284faa1acc static inline decls.
Claus Gittinger <cg@exept.de>
parents: 23958
diff changeset
    89
STATIC_INLINE void SHA1Init();
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    90
 void SHA1Update();
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    91
 void SHA1Final();
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    92
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
    93
#endif /* USE_ANSI_C */
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
    94
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    95
%}
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    96
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    97
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    98
!SHA1Stream primitiveFunctions!
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
    99
%{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   100
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   101
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   102
 * SHA-1 in C
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   103
 * By Steve Reid <steve@edmweb.com>
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   104
 * 100% Public Domain
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   105
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   106
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   107
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   108
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   109
/* blk0() and blk() perform the initial expand. */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   110
/* I got the idea of expanding during the round function from SSLeay */
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   111
// 876543210 -> rol,24 -> 108765432 -> & -> 10xx65xx
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   112
// 876543210 -> rol,8  -> 654321087 -> & -> xx43xx87
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   113
// oring: 10436587
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   114
#ifdef LITTLE_ENDIAN
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   115
// cg: does not make any difference (actually, slightly slower, as it seems)...
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   116
# if 0 && (defined(__i386__) || defined(__x86__) || defined(__x86_64__)) && (defined(__GNUC__) || defined(__CLANG__))
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   117
   static inline u_int32_t __bswap(u_int32_t v) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   118
	register u_int32_t l = v;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   119
	__asm__ __volatile__("bswap %0" : "=r" (l) : "0" (l));
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   120
	return l;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   121
   }
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   122
#  define blk0(i) \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   123
    (block->l[i] = __bswap(block->l[i]))
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   124
# else
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   125
#  define blk0(i) \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   126
    (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   127
		  |(rol(block->l[i],8)&0x00FF00FF))
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   128
# endif
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   129
#else
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   130
# define blk0(i) block->l[i]
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   131
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   132
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   133
#define blk(i) (block->l[i&15] = \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   134
    rol(block->l[(i+13)&15] \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   135
	^ block->l[(i+8)&15] \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   136
	^ block->l[(i+2)&15] \
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   137
	^ block->l[i&15],1))
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   138
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   139
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   140
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   141
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   142
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   143
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   144
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   145
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   146
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   147
 * Hash a single 512-bit block. This is the core of the algorithm.
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   148
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   149
static void
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   150
#if USE_ANSI_C
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   151
SHA1Transform_generic (unsigned int32 state[5], unsigned char buffer[64])
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   152
#else
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   153
SHA1Transform_generic (state, buffer)
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   154
    unsigned int32 state[5];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   155
    unsigned char buffer[64];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   156
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   157
{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   158
    unsigned int32 a, b, c, d, e;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   159
    typedef union {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   160
	unsigned char c[64];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   161
	unsigned int32 /* long */ l[16];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   162
    } CHAR64LONG16;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   163
    CHAR64LONG16* block;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   164
#ifdef SHA1HANDSOFF
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   165
    static unsigned char workspace[64];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   166
    block = (CHAR64LONG16*)workspace;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   167
    memcpy(block, buffer, 64);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   168
#else
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   169
    block = (CHAR64LONG16*)buffer;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   170
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   171
    /* Copy context->state[] to working vars */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   172
    a = state[0];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   173
    b = state[1];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   174
    c = state[2];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   175
    d = state[3];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   176
    e = state[4];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   177
    /* 4 rounds of 20 operations each. Loop unrolled. */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   178
    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   179
    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   180
    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   181
    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   182
    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   183
    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   184
    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   185
    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   186
    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   187
    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   188
    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   189
    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   190
    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   191
    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   192
    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   193
    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   194
    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   195
    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   196
    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   197
    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   198
    /* Add the working vars back into context.state[] */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   199
    state[0] += a;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   200
    state[1] += b;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   201
    state[2] += c;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   202
    state[3] += d;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   203
    state[4] += e;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   204
    /* Wipe variables */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   205
    a = b = c = d = e = 0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   206
}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   207
23958
1c903aa4a100 compilation fixes
Claus Gittinger <cg@exept.de>
parents: 23957
diff changeset
   208
#if defined(USE_SHA_INTRINSICS)
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   209
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   210
//
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   211
// a specially tuned version
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   212
//
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   213
static void
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   214
SHA1Transform_x86 (unsigned int32 state[5], unsigned char buffer[64])
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   215
{
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   216
    unsigned int32 a, b, c, d, e;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   217
    typedef union {
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   218
	unsigned char c[64];
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   219
	unsigned int32 /* long */ l[16];
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   220
    } CHAR64LONG16;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   221
    CHAR64LONG16* block;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   222
#ifdef SHA1HANDSOFF
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   223
    static unsigned char workspace[64];
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   224
    block = (CHAR64LONG16*)workspace;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   225
    memcpy(block, buffer, 64);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   226
#else
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   227
    block = (CHAR64LONG16*)buffer;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   228
#endif
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   229
    __m128i ABCD, ABCD_SAVE, E0, E0_SAVE, E1;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   230
    __m128i MSG0, MSG1, MSG2, MSG3;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   231
    const __m128i MASK = _mm_set_epi64x(0x0001020304050607ULL, 0x08090a0b0c0d0e0fULL);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   232
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   233
    /* Load initial values */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   234
    ABCD = _mm_loadu_si128((const __m128i*) state);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   235
    E0 = _mm_set_epi32(state[4], 0, 0, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   236
    ABCD = _mm_shuffle_epi32(ABCD, 0x1B);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   237
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   238
	/* Save current state  */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   239
	ABCD_SAVE = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   240
	E0_SAVE = E0;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   241
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   242
	/* Rounds 0-3 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   243
	MSG0 = _mm_loadu_si128((const __m128i*)(block + 0));
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   244
	MSG0 = _mm_shuffle_epi8(MSG0, MASK);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   245
	E0 = _mm_add_epi32(E0, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   246
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   247
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   248
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   249
	/* Rounds 4-7 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   250
	MSG1 = _mm_loadu_si128((const __m128i*)(block + 16));
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   251
	MSG1 = _mm_shuffle_epi8(MSG1, MASK);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   252
	E1 = _mm_sha1nexte_epu32(E1, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   253
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   254
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   255
	MSG0 = _mm_sha1msg1_epu32(MSG0, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   256
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   257
	/* Rounds 8-11 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   258
	MSG2 = _mm_loadu_si128((const __m128i*)(block + 32));
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   259
	MSG2 = _mm_shuffle_epi8(MSG2, MASK);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   260
	E0 = _mm_sha1nexte_epu32(E0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   261
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   262
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   263
	MSG1 = _mm_sha1msg1_epu32(MSG1, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   264
	MSG0 = _mm_xor_si128(MSG0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   265
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   266
	/* Rounds 12-15 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   267
	MSG3 = _mm_loadu_si128((const __m128i*)(block + 48));
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   268
	MSG3 = _mm_shuffle_epi8(MSG3, MASK);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   269
	E1 = _mm_sha1nexte_epu32(E1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   270
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   271
	MSG0 = _mm_sha1msg2_epu32(MSG0, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   272
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   273
	MSG2 = _mm_sha1msg1_epu32(MSG2, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   274
	MSG1 = _mm_xor_si128(MSG1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   275
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   276
	/* Rounds 16-19 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   277
	E0 = _mm_sha1nexte_epu32(E0, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   278
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   279
	MSG1 = _mm_sha1msg2_epu32(MSG1, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   280
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   281
	MSG3 = _mm_sha1msg1_epu32(MSG3, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   282
	MSG2 = _mm_xor_si128(MSG2, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   283
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   284
	/* Rounds 20-23 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   285
	E1 = _mm_sha1nexte_epu32(E1, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   286
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   287
	MSG2 = _mm_sha1msg2_epu32(MSG2, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   288
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   289
	MSG0 = _mm_sha1msg1_epu32(MSG0, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   290
	MSG3 = _mm_xor_si128(MSG3, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   291
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   292
	/* Rounds 24-27 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   293
	E0 = _mm_sha1nexte_epu32(E0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   294
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   295
	MSG3 = _mm_sha1msg2_epu32(MSG3, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   296
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   297
	MSG1 = _mm_sha1msg1_epu32(MSG1, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   298
	MSG0 = _mm_xor_si128(MSG0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   299
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   300
	/* Rounds 28-31 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   301
	E1 = _mm_sha1nexte_epu32(E1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   302
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   303
	MSG0 = _mm_sha1msg2_epu32(MSG0, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   304
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   305
	MSG2 = _mm_sha1msg1_epu32(MSG2, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   306
	MSG1 = _mm_xor_si128(MSG1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   307
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   308
	/* Rounds 32-35 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   309
	E0 = _mm_sha1nexte_epu32(E0, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   310
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   311
	MSG1 = _mm_sha1msg2_epu32(MSG1, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   312
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   313
	MSG3 = _mm_sha1msg1_epu32(MSG3, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   314
	MSG2 = _mm_xor_si128(MSG2, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   315
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   316
	/* Rounds 36-39 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   317
	E1 = _mm_sha1nexte_epu32(E1, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   318
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   319
	MSG2 = _mm_sha1msg2_epu32(MSG2, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   320
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   321
	MSG0 = _mm_sha1msg1_epu32(MSG0, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   322
	MSG3 = _mm_xor_si128(MSG3, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   323
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   324
	/* Rounds 40-43 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   325
	E0 = _mm_sha1nexte_epu32(E0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   326
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   327
	MSG3 = _mm_sha1msg2_epu32(MSG3, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   328
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   329
	MSG1 = _mm_sha1msg1_epu32(MSG1, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   330
	MSG0 = _mm_xor_si128(MSG0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   331
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   332
	/* Rounds 44-47 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   333
	E1 = _mm_sha1nexte_epu32(E1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   334
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   335
	MSG0 = _mm_sha1msg2_epu32(MSG0, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   336
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   337
	MSG2 = _mm_sha1msg1_epu32(MSG2, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   338
	MSG1 = _mm_xor_si128(MSG1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   339
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   340
	/* Rounds 48-51 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   341
	E0 = _mm_sha1nexte_epu32(E0, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   342
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   343
	MSG1 = _mm_sha1msg2_epu32(MSG1, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   344
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   345
	MSG3 = _mm_sha1msg1_epu32(MSG3, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   346
	MSG2 = _mm_xor_si128(MSG2, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   347
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   348
	/* Rounds 52-55 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   349
	E1 = _mm_sha1nexte_epu32(E1, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   350
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   351
	MSG2 = _mm_sha1msg2_epu32(MSG2, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   352
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   353
	MSG0 = _mm_sha1msg1_epu32(MSG0, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   354
	MSG3 = _mm_xor_si128(MSG3, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   355
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   356
	/* Rounds 56-59 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   357
	E0 = _mm_sha1nexte_epu32(E0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   358
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   359
	MSG3 = _mm_sha1msg2_epu32(MSG3, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   360
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   361
	MSG1 = _mm_sha1msg1_epu32(MSG1, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   362
	MSG0 = _mm_xor_si128(MSG0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   363
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   364
	/* Rounds 60-63 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   365
	E1 = _mm_sha1nexte_epu32(E1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   366
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   367
	MSG0 = _mm_sha1msg2_epu32(MSG0, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   368
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   369
	MSG2 = _mm_sha1msg1_epu32(MSG2, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   370
	MSG1 = _mm_xor_si128(MSG1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   371
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   372
	/* Rounds 64-67 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   373
	E0 = _mm_sha1nexte_epu32(E0, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   374
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   375
	MSG1 = _mm_sha1msg2_epu32(MSG1, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   376
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   377
	MSG3 = _mm_sha1msg1_epu32(MSG3, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   378
	MSG2 = _mm_xor_si128(MSG2, MSG0);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   379
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   380
	/* Rounds 68-71 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   381
	E1 = _mm_sha1nexte_epu32(E1, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   382
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   383
	MSG2 = _mm_sha1msg2_epu32(MSG2, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   384
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   385
	MSG3 = _mm_xor_si128(MSG3, MSG1);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   386
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   387
	/* Rounds 72-75 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   388
	E0 = _mm_sha1nexte_epu32(E0, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   389
	E1 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   390
	MSG3 = _mm_sha1msg2_epu32(MSG3, MSG2);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   391
	ABCD = _mm_sha1rnds4_epu32(ABCD, E0, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   392
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   393
	/* Rounds 76-79 */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   394
	E1 = _mm_sha1nexte_epu32(E1, MSG3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   395
	E0 = ABCD;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   396
	ABCD = _mm_sha1rnds4_epu32(ABCD, E1, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   397
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   398
	/* Combine state */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   399
	E0 = _mm_sha1nexte_epu32(E0, E0_SAVE);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   400
	ABCD = _mm_add_epi32(ABCD, ABCD_SAVE);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   401
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   402
    /* Save state */
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   403
    ABCD = _mm_shuffle_epi32(ABCD, 0x1B);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   404
    _mm_storeu_si128((__m128i*) state, ABCD);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   405
    state[4] = _mm_extract_epi32(E0, 3);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   406
}
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   407
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   408
static void
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   409
#if USE_ANSI_C
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   410
SHA1Transform(unsigned int32 state[5], unsigned char buffer[64])
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   411
#else
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   412
SHA1Transform(state, buffer)
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   413
    unsigned int32 state[5];
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   414
    unsigned char buffer[64];
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   415
#endif
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   416
{
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   417
    extern unsigned char __cpu_hasSSE4_1_and_SHA;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   418
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   419
    if (__cpu_hasSSE4_1_and_SHA) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   420
	SHA1Transform_x86(state, buffer);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   421
    } else {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   422
	SHA1Transform_generic(state, buffer);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   423
    }
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   424
}
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   425
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   426
#endif
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   427
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   428
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   429
 * SHA1Init - Initialize new context
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   430
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   431
STATIC_INLINE void
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   432
#if USE_ANSI_C
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   433
SHA1Init(SHA1_CTX* context)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   434
#else
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   435
SHA1Init(context)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   436
    SHA1_CTX* context;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   437
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   438
{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   439
    /* SHA1 initialization constants */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   440
    context->state[0] = 0x67452301;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   441
    context->state[1] = 0xEFCDAB89;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   442
    context->state[2] = 0x98BADCFE;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   443
    context->state[3] = 0x10325476;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   444
    context->state[4] = 0xC3D2E1F0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   445
    context->count[0] = context->count[1] = 0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   446
}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   447
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   448
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   449
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   450
 * Run your data through this.
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   451
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   452
void
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   453
#if USE_ANSI_C
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   454
SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   455
#else
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   456
SHA1Update(context, data, len)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   457
    SHA1_CTX* context;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   458
    unsigned char* data;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   459
    unsigned int len;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   460
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   461
{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   462
    unsigned int i, j;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   463
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   464
    j = (context->count[0] >> 3) & 63;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   465
    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   466
    context->count[1] += (len >> 29);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   467
    if ((j + len) > 63) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   468
	memcpy(&context->buffer[j], data, (i = 64-j));
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   469
	SHA1Transform(context->state, context->buffer);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   470
	for ( ; i + 63 < len; i += 64) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   471
	    SHA1Transform(context->state, &data[i]);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   472
	}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   473
	j = 0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   474
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   475
    else i = 0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   476
    memcpy(&context->buffer[j], &data[i], len - i);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   477
}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   478
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   479
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   480
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   481
 * Add padding and return the message digest.
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   482
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   483
void
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   484
#if USE_ANSI_C
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   485
SHA1Final(unsigned char digest[20], SHA1_CTX* context)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   486
#else
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   487
SHA1Final(digest, context)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   488
    unsigned char digest[20];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   489
    SHA1_CTX* context;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   490
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   491
{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   492
    unsigned int32 i, j;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   493
    unsigned char finalcount[8];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   494
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   495
    for (i = 0; i < 8; i++) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   496
	finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   497
	 >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   498
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   499
    SHA1Update(context, (unsigned char *)"\200", 1);
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   500
    while ((context->count[0] & 504 /* 16r1F8 */) != 448 /* 16r1C0 */) {
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   501
	SHA1Update(context, (unsigned char *)"\0", 1);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   502
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   503
    SHA1Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   504
    for (i = 0; i < 20; i++) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   505
	digest[i] = (unsigned char)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   506
	 ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   507
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   508
    /* Wipe variables */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   509
    i = j = 0;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   510
    memset(context->buffer, 0, 64);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   511
    memset(context->state, 0, 20);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   512
    memset(context->count, 0, 8);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   513
    memset(&finalcount, 0, 8);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   514
#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   515
    SHA1Transform(context->state, context->buffer);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   516
#endif
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   517
}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   518
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   519
#if 0
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   520
/*************************************************************/
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   521
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   522
/*
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   523
 * SHA1 test program
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   524
 */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   525
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   526
int main(int argc, char** argv)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   527
{
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   528
    int i, j;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   529
    SHA1_CTX context;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   530
    unsigned char digest[20], buffer[16384];
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   531
    FILE* file;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   532
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   533
    if (argc > 2) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   534
	puts("Public domain SHA-1 implementation - by Steve Reid <steve@edmweb.com>");
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   535
	puts("Produces the SHA-1 hash of a file, or stdin if no file is specified.");
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   536
	exit(0);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   537
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   538
    if (argc < 2) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   539
	file = stdin;
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   540
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   541
    else {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   542
	if (!(file = fopen(argv[1], "rb"))) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   543
	    fputs("Unable to open file.", stderr);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   544
	    exit(-1);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   545
	}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   546
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   547
    SHA1Init(&context);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   548
    while (!feof(file)) {  /* note: what if ferror(file) */
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   549
	i = fread(buffer, 1, 16384, file);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   550
	SHA1Update(&context, buffer, i);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   551
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   552
    SHA1Final(digest, &context);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   553
    fclose(file);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   554
    for (i = 0; i < 5; i++) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   555
	for (j = 0; j < 4; j++) {
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   556
	    printf("%02X", digest[i*4+j]);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   557
	}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   558
	putchar(' ');
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   559
    }
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   560
    putchar('\n');
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   561
    exit(0);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   562
}
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   563
#endif
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   564
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   565
%}
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   566
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   567
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   568
!SHA1Stream class methodsFor:'documentation'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   569
4426
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   570
copyright
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   571
"
15038
22f613e86520 class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15025
diff changeset
   572
 COPYRIGHT (c) 1999-2013 by eXept Software AG
15907
b6a05f7d463f use int32 instead of long (for 64bit machines)
Claus Gittinger <cg@exept.de>
parents: 15623
diff changeset
   573
	      All Rights Reserved
4426
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   574
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   575
 This software is furnished under a license and may be used
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   576
 only in accordance with the terms of that license and with the
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   577
 inclusion of the above copyright notice.   This software may not
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   578
 be provided or otherwise made available to, or used by, any
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   579
 other person.  No title to or ownership of the software is
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   580
 hereby transferred.
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   581
"
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   582
!
87994187176a documentation
Claus Gittinger <cg@exept.de>
parents: 4051
diff changeset
   583
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   584
documentation
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   585
"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   586
    Generate a SHA-1 hash value as defined in
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   587
    NIST, FIPS PUB 180-1: Secure Hash Standard, April 1995.
13933
b2c5cb0eebbd changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 13930
diff changeset
   588
13935
0d7929973c93 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 13934
diff changeset
   589
    Notice (2005):
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   590
	Be aware that SHA-1 is considered broken and may not be appropriate in some applications.
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   591
	Especially it should no longer be used for security stuff.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   592
12265
Claus Gittinger <cg@exept.de>
parents: 12257
diff changeset
   593
    performance: roughly
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   594
	  200 Mb/s on a 2012 MAC Powerbook (2.6Ghz I7)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   595
	  150 Mb/s on a 2007 MAC Powerbook (2.6Ghz Duo)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   596
	  120 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   597
	   47400 Kb/s on a 2Ghz Duo (old measure)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   598
	    9580 Kb/s on a 400Mhz PIII
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   599
	    3970 Kb/s on a 300Mhz Sparc
4916
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   600
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   601
    [author:]
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   602
	Stefan Vogel
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   603
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   604
    [see also:]
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   605
	MD5Stream
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   606
	SHA256Stream SHA512Stream (in libcrypt)
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   607
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   608
    [class variables:]
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   609
	HashSize        size of returned hash value
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   610
	ContextSize     (implementation) size of hash context
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   611
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   612
    [instance variables:]
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   613
	hashContext     (implementation)
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   614
			internal buffer for computation of the hash value
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   615
"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   616
!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   617
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   618
examples
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   619
"
10781
322a34a50825 comments
Claus Gittinger <cg@exept.de>
parents: 9369
diff changeset
   620
    Test Vectors (from FIPS PUB 180-1); results are:
7824
7361f26d98cb code indentation
Claus Gittinger <cg@exept.de>
parents: 7045
diff changeset
   621
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   622
								[exBegin]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   623
    |hashStream|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   624
4798
9057c002734a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4797
diff changeset
   625
    hashStream := SHA1Stream new.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   626
    hashStream nextPut:'abc'.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   627
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   628
    hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   629
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   630
								[exEnd]
19160
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
   631
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   632
								[exBegin]
19160
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
   633
    |hashValue|
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   634
19160
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
   635
    hashValue := SHA1Stream hashValueOf:'hello world'.
e31658d8c07c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19143
diff changeset
   636
    self assert:(hashValue hexPrintString = '2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED')
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   637
								[exEnd]
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   638
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   639
								[exBegin]
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   640
    |hashValue|
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   641
15038
22f613e86520 class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15025
diff changeset
   642
    hashValue := SHA1Stream hashValueOf:'abc'.
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   643
    hashValue printOn:Transcript base:16. Transcript cr.
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   644
								[exEnd]
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   645
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   646
								[exBegin]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   647
    |hashStream|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   648
4798
9057c002734a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4797
diff changeset
   649
    hashStream := SHA1Stream new.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   650
    hashStream nextPut:'abc' asByteArray.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   651
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   652
    hashStream nextPut:'dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' asByteArray.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   653
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   654
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   655
								[exEnd]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   656
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   657
								[exBegin]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   658
    |hashStream|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   659
4798
9057c002734a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4797
diff changeset
   660
    hashStream := SHA1Stream new.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   661
    1000000 timesRepeat:[ hashStream nextPut:$a ].
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   662
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   663
								[exEnd]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   664
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   665
								[exBegin]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   666
    |hashStream|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   667
4798
9057c002734a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4797
diff changeset
   668
    hashStream := SHA1Stream new.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   669
    hashStream nextPut:'a'.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   670
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   671
								[exEnd]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   672
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   673
								[exBegin]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   674
    |hashStream|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   675
4798
9057c002734a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4797
diff changeset
   676
    hashStream := SHA1Stream new.
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   677
    hashStream nextPut:$a.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   678
    hashStream hashValue printOn:Transcript base:16. Transcript cr.
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   679
								[exEnd]
4916
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   680
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   681
  timing throughput:
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   682
								[exBegin]
4916
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   683
    |hashStream n t|
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   684
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   685
    hashStream := SHA1Stream new.
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   686
    n := 1000000.
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   687
    t := Time millisecondsToRun:[
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   688
	    n timesRepeat:[
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   689
		hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   690
	    ].
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   691
	 ].
4916
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   692
    t := (t / 1000) asFloat.
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   693
    Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
df965a3448b9 added throughput test example
Claus Gittinger <cg@exept.de>
parents: 4798
diff changeset
   694
    Transcript show:(n*50/1024 / t); showCR:' Kb/s'
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   695
								[exEnd]
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   696
"
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   697
!
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   698
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   699
performance
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   700
"
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
   701
    CPU                             cc          algo        mb/sec
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   702
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
   703
    MAC (2010 macbook; 2.7Ghz Duo)  clang -O2   slow        128.5
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   704
							    132
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   705
    MAC (2012 macbook; 2.6Ghz I7)   clang -O2               190
23952
59e081dd12dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23937
diff changeset
   706
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   707
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   708
    chunk size 10:     86.70 Mb/s   90.83
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   709
    chunk size 50:    227.07 Mb/s  238.42
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   710
    chunk size 1000:  405.82 Mb/s  414.64
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   711
    chunk size 50000: 421.98 Mb/s  447.73
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   712
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   713
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   714
  timing throughput:
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   715
								[exBegin]
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   716
    |hashStream n t|
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   717
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   718
    hashStream := SHA1Stream new.
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   719
    n := 1000000.
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   720
    t := Time millisecondsToRun:[
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   721
	    n timesRepeat:[
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   722
		hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   723
	    ].
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   724
	 ].
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   725
    t := (t / 1000) asFloat.
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   726
    Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   727
    Transcript show:(n*50/1024 / t); showCR:' Kb/s'
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   728
								[exEnd]
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   729
"
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   730
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   731
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   732
!SHA1Stream class methodsFor:'initialization'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   733
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   734
initialize
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   735
    |ctxSize|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   736
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   737
%{
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   738
    ctxSize = __MKSMALLINT(sizeof(SHA1_CTX));
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   739
%}.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   740
    ContextSize := ctxSize.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   741
    HashSize := 20.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   742
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   743
    "
5056
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
   744
	self initialize
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   745
    "
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   746
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   747
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   748
!SHA1Stream class methodsFor:'queries'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   749
15623
1c229b466d52 Rename #blockSize to #hashBlockSize
Stefan Vogel <sv@exept.de>
parents: 15038
diff changeset
   750
hashBlockSize
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   751
    "return the block size used internally by the compression function"
15907
b6a05f7d463f use int32 instead of long (for 64bit machines)
Claus Gittinger <cg@exept.de>
parents: 15623
diff changeset
   752
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   753
    ^ 64
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   754
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   755
    "Created: / 18.3.1999 / 08:37:10 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   756
!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   757
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   758
hashSize
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   759
    "return the size of the hashvalue returned by instances of this class"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   760
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   761
    ^ HashSize
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   762
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   763
    "Modified: / 18.3.1999 / 07:54:22 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   764
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   765
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   766
!SHA1Stream methodsFor:'initialization'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   767
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   768
initialize
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   769
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   770
    hashContext := ByteArray new:ContextSize.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   771
    self reset
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   772
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   773
    "Created: / 17.3.1999 / 16:11:37 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   774
    "Modified: / 18.3.1999 / 07:56:46 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   775
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   776
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   777
!SHA1Stream methodsFor:'positioning'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   778
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   779
reset
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   780
   "reset the stream in order to compute a new hash value"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   781
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   782
%{
14669
932dd50e11a7 code cleanup
Claus Gittinger <cg@exept.de>
parents: 14667
diff changeset
   783
   if (__isByteArray(__INST(hashContext)) &&
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   784
       __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   785
   ) {
14667
f6a830b971f3 care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents: 13935
diff changeset
   786
	SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   787
14667
f6a830b971f3 care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents: 13935
diff changeset
   788
	SHA1Init(ctx);
f6a830b971f3 care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents: 13935
diff changeset
   789
	RETURN(self);
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   790
   }
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   791
%}.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   792
   ^ self primitiveFailed
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   793
13930
7ae7e5793dd5 changed: #reset
Claus Gittinger <cg@exept.de>
parents: 13926
diff changeset
   794
    "Created: / 18-03-1999 / 07:59:02 / stefan"
7ae7e5793dd5 changed: #reset
Claus Gittinger <cg@exept.de>
parents: 13926
diff changeset
   795
    "Modified: / 12-01-2012 / 12:21:23 / cg"
22563
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   796
!
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   797
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   798
seedWith:fiveWordVector
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   799
   "seed the stream with 5*16  (for testing)"
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   800
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   801
    |seedA seedB seedC seedD seedE|
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   802
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   803
    seedA := fiveWordVector at:1.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   804
    seedB := fiveWordVector at:1.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   805
    seedC := fiveWordVector at:1.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   806
    seedD := fiveWordVector at:1.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   807
    seedE := fiveWordVector at:1.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   808
    self reset.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   809
%{
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   810
   if (__isByteArray(__INST(hashContext))
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   811
    && (__byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX))
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   812
    && __isSmallInteger(seedA)
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   813
    && __isSmallInteger(seedB)
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   814
    && __isSmallInteger(seedC)
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   815
    && __isSmallInteger(seedD)
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   816
    && __isSmallInteger(seedE)
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   817
   ) {
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   818
	SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
22563
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   819
23953
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   820
	ctx->state[0] = __intVal(seedA);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   821
	ctx->state[1] = __intVal(seedB);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   822
	ctx->state[2] = __intVal(seedC);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   823
	ctx->state[3] = __intVal(seedD);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   824
	ctx->state[4] = __intVal(seedE);
43aef89d0166 CVS merge bug
Claus Gittinger <cg@exept.de>
parents: 23952
diff changeset
   825
	RETURN(self);
22563
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   826
   }
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   827
%}.
7ab243018a90 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
   828
   ^ self primitiveFailed
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   829
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   830
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   831
!SHA1Stream methodsFor:'queries'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   832
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   833
hashValue
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   834
    "Get the value hashed so far.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   835
     The context is kept, so that more objects may be hashed after
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   836
     retrieving a hash value"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   837
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   838
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   839
    |digest|
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   840
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   841
    digest := ByteArray new:HashSize.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   842
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   843
%{
14791
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   844
    OBJ hcon;
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   845
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   846
    hcon = __INST(hashContext);
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   847
    if (__isByteArray(hcon) &&
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   848
	__byteArraySize(hcon) == sizeof(SHA1_CTX) &&
14669
932dd50e11a7 code cleanup
Claus Gittinger <cg@exept.de>
parents: 14667
diff changeset
   849
	__isByteArray(digest) &&
5056
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
   850
	__byteArraySize(digest) == 20
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   851
    ) {
14791
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   852
	SHA1_CTX *ctx = (SHA1_CTX *)(__ByteArrayInstPtr(hcon)->ba_element);
5056
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
   853
	SHA1_CTX copyContext;
14723
8657c48a4c03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14715
diff changeset
   854
14791
4bd37b3efdb2 int32 vs. long fix
Claus Gittinger <cg@exept.de>
parents: 14788
diff changeset
   855
	memcpy(&copyContext, ctx, sizeof(SHA1_CTX));
5056
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
   856
	SHA1Final(__ByteArrayInstPtr(digest)->ba_element, &copyContext);
161b8aaf00eb Fix alignment in SHA1Stream"
Stefan Vogel <sv@exept.de>
parents: 4926
diff changeset
   857
	RETURN(digest);
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   858
    }
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   859
%}.
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   860
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   861
    ^ self primitiveFailed
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   862
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   863
    "Created: / 17.3.1999 / 16:13:12 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   864
    "Modified: / 18.3.1999 / 08:00:54 / stefan"
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   865
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   866
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   867
!SHA1Stream methodsFor:'writing'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   868
19400
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   869
nextPutByte:anInteger
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   870
    "update the hash value with anInteger <= 255."
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   871
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   872
%{
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   873
   unsigned char value;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   874
   OBJ _hashContext = __INST(hashContext);
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   875
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   876
   // fetch first; check below
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   877
   value = __intVal(anInteger);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   878
   if (__isSmallInteger(anInteger) && value <= 255
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   879
       && __isByteArray(_hashContext)
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   880
       && __byteArraySize(_hashContext) == sizeof(SHA1_CTX)
19400
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   881
   ) {
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   882
	SHA1_CTX *ctx = (SHA1_CTX *)__byteArrayVal(_hashContext);
19400
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   883
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   884
	SHA1Update(ctx, &value, 1);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   885
	RETURN(self);
19400
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   886
    }
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   887
bad: ;
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   888
%}.
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   889
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   890
    ^ self primitiveFailed
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   891
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   892
    "Modified: / 23-03-2019 / 15:19:40 / Claus Gittinger"
19400
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   893
!
730bc6efb733 new: #nextPutByte:
Stefan Vogel <sv@exept.de>
parents: 19160
diff changeset
   894
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   895
nextPutBytes:count from:anObject startingAt:start
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   896
    "update the hash value with count bytes from an object starting at index start.
9369
b7f43a51c4ed Moved SHA1Stream from exept:libcrypt to stx:libbasic
Stefan Vogel <sv@exept.de>
parents: 7824
diff changeset
   897
     The object must have non-pointer indexed instvars
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   898
     (i.e. be a ByteArray, String, Float- or DoubleArray),
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   899
     or an externalBytes object (with known size)"
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   900
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   901
%{
14667
f6a830b971f3 care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents: 13935
diff changeset
   902
    INT len, offs;
f6a830b971f3 care for externalAddress being NULL before accessing an external buffer's contents
Claus Gittinger <cg@exept.de>
parents: 13935
diff changeset
   903
    INT objSize;
15989
824d113634fc class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15907
diff changeset
   904
    int nInstBytes;
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   905
    unsigned char *extPtr;
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   906
    OBJ _hashContext = __INST(hashContext);
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   907
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   908
    // convert here; check later
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   909
    len = __intVal(count);
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   910
    offs = __intVal(start) - 1;
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   911
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   912
    if (__isByteArray(_hashContext)
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   913
       && __byteArraySize(_hashContext) == sizeof(SHA1_CTX)
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   914
       && __bothSmallInteger(count, start)
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   915
    ) {
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   916
	SHA1_CTX *ctx = (SHA1_CTX *)__byteArrayVal(_hashContext);
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   917
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   918
	if (__isByteArrayLike(anObject)) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   919
	    extPtr = (unsigned char *)__byteArrayVal(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   920
	    objSize = __byteArraySize(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   921
	} else if (__isStringLike(anObject)) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   922
	    extPtr = (unsigned char *)__stringVal(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   923
	    objSize = __stringSize(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   924
	} else if (__isExternalBytesLike(anObject)) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   925
	    OBJ sz;
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   926
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   927
	    nInstBytes = 0;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   928
	    extPtr = (unsigned char *)__externalBytesAddress(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   929
	    if (extPtr == NULL) goto bad;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   930
	    sz = __externalBytesSize(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   931
	    objSize = __intVal(sz);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   932
	    if (!__isSmallInteger(sz)) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   933
		objSize = 0; /* unknown */
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   934
	    }
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   935
	} else {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   936
	    OBJ oClass = __Class(anObject);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   937
	    int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
14723
8657c48a4c03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14715
diff changeset
   938
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   939
	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   940
	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   941
		case BYTEARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   942
		case WORDARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   943
		case LONGARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   944
		case SWORDARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   945
		case SLONGARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   946
		case FLOATARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   947
		    break;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   948
		case DOUBLEARRAY:
15989
824d113634fc class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15907
diff changeset
   949
#ifdef __NEED_DOUBLE_ALIGN
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   950
		    nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
15989
824d113634fc class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15907
diff changeset
   951
#endif
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   952
		    break;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   953
		case LONGLONGARRAY:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   954
		case SLONGLONGARRAY:
15989
824d113634fc class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15907
diff changeset
   955
#ifdef __NEED_LONGLONG_ALIGN
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   956
		    nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
15989
824d113634fc class: SHA1Stream
Stefan Vogel <sv@exept.de>
parents: 15907
diff changeset
   957
#endif
23957
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   958
		    break;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   959
		default:
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   960
		    goto bad;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   961
	    }
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   962
	    // nInstBytes is the number of bytes occupied by pointer instance variables
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   963
	    // subtract from size and add to byte-pointer
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   964
	    objSize = __Size(anObject) - nInstBytes;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   965
	    extPtr = (unsigned char *)anObject + nInstBytes;
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   966
	}
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   967
	if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   968
	    SHA1Update(ctx, extPtr+offs, (unsigned int)len);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   969
	    RETURN (count);
0094f9be672e sha instruction support
Claus Gittinger <cg@exept.de>
parents: 23956
diff changeset
   970
	}
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   971
    }
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   972
bad: ;
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   973
%}.
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   974
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   975
    ^ self primitiveFailed
23956
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   976
22c01d2b1186 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23953
diff changeset
   977
    "Modified: / 23-03-2019 / 15:28:31 / Claus Gittinger"
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   978
! !
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   979
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   980
!SHA1Stream class methodsFor:'documentation'!
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   981
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   982
version
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   983
    ^ '$Header$'
12205
89063d394d63 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 10781
diff changeset
   984
!
89063d394d63 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 10781
diff changeset
   985
89063d394d63 changed: #documentation
Claus Gittinger <cg@exept.de>
parents: 10781
diff changeset
   986
version_CVS
19143
8096983985e5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16009
diff changeset
   987
    ^ '$Header$'
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   988
! !
7042
dbb7898901e3 Fix #hashValueOf:
Stefan Vogel <sv@exept.de>
parents: 6789
diff changeset
   989
14715
8a6c43a26ca1 class: SHA1Stream
Claus Gittinger <cg@exept.de>
parents: 14675
diff changeset
   990
4051
87de5a78e265 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   991
SHA1Stream initialize!