1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>NeL: sha1.cpp File Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex"> <form class="search" action="search.php" method="get">
<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<h1>sha1.cpp File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
This file implements the Secure Hashing Algorithm 1 as defined in FIPS PUB 180-1 published April 17, 1995.<p>
The SHA-1, produces a 160-bit message digest for a given data stream. It should take about 2**n steps to find a message with the same digest as a given message and 2**(n/2) to find any two messages with the same digest, when n is the digest size in bits. Therefore, this algorithm can serve as a means of providing a "fingerprint" for a message.<p>
Portability Issues: SHA-1 is defined in terms of 32-bit "words". This code uses <stdint.h> (included via "sha1.h" to define 32 and 8 bit unsigned integer types. If your C compiler does not support 32 bit unsigned integers, this code is not appropriate.<p>
Caveats: SHA-1 is designed to work with messages less than 2^64 bits long. Although SHA-1 allows a message digest to be generated for messages of any number of bits less than 2^64, this implementation only works with messages with a length that is a multiple of the size of an 8-bit character.<p>
<dl compact><dt><b>Id</b></dt><dd><a class="el" href="a04943.html">sha1.cpp</a>,v 1.4 2003/10/20 16:10:17 lecroart Exp </dd></dl>
<p>
Definition in file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
<code>#include "<a class="el" href="a06444.html">stdmisc.h</a>"</code><br>
<code>#include <stdio.h></code><br>
<code>#include <string.h></code><br>
<code>#include <string></code><br>
<code>#include <map></code><br>
<code>#include <vector></code><br>
<code>#include "<a class="el" href="a06367.html">nel/misc/sha1.h</a>"</code><br>
<code>#include "<a class="el" href="a05709.html">nel/misc/file.h</a>"</code><br>
<code>#include "<a class="el" href="a06168.html">nel/misc/path.h</a>"</code><br>
<p>
<a href="a06366.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Data Structures</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>struct </td><td class="memItemRight" valign=bottom><a class="el" href="a03895.html">SHA1Context</a></td></tr>
<tr><td colspan=2><br><h2>Defines</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a1">SHA1CircularShift</a>(bits, word) (((word) << (bits)) | ((word) >> (32-(bits))))</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a0">SHA1HashSize</a> 20</td></tr>
<tr><td colspan=2><br><h2>Typedefs</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>typedef short </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a4">int_least16_t</a></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>typedef <a class="el" href="a03895.html">SHA1Context</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a7">SHA1Context</a></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>typedef unsigned int </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a2">uint32_t</a></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>typedef unsigned char </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a3">uint8_t</a></td></tr>
<tr><td colspan=2><br><h2>Enumerations</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>enum </td><td class="memItemRight" valign=bottom>{ <a class="el" href="a04943.html#a19a8">shaSuccess</a> = 0,
<a class="el" href="a04943.html#a19a9">shaNull</a>,
<a class="el" href="a04943.html#a19a10">shaInputTooLong</a>,
<a class="el" href="a04943.html#a19a11">shaStateError</a>
}</td></tr>
<tr><td colspan=2><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a02607.html">CHashKey</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a16">getSHA1</a> (const string &<a class="el" href="a04560.html#a1">filename</a>)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a02607.html">CHashKey</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a15">getSHA1</a> (const <a class="el" href="a04558.html#a7">uint8</a> *<a class="el" href="a04223.html#a589">buffer</a>, <a class="el" href="a04558.html#a11">uint32</a> <a class="el" href="a04223.html#a587">size</a>)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a13">SHA1Input</a> (<a class="el" href="a03895.html">SHA1Context</a> *, const <a class="el" href="a04943.html#a3">uint8_t</a> *, unsigned int)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a17">SHA1PadMessage</a> (<a class="el" href="a03895.html">SHA1Context</a> *)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a18">SHA1ProcessMessageBlock</a> (<a class="el" href="a03895.html">SHA1Context</a> *)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a12">SHA1Reset</a> (<a class="el" href="a03895.html">SHA1Context</a> *)</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a14">SHA1Result</a> (<a class="el" href="a03895.html">SHA1Context</a> *, <a class="el" href="a04943.html#a3">uint8_t</a> Message_Digest[20])</td></tr>
<tr><td colspan=2><br><h2>Variables</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a04943.html#a3">uint8_t</a> </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a6">buffer</a> [<a class="el" href="a04943.html#a5">bufferSize</a>]</td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>const int </td><td class="memItemRight" valign=bottom><a class="el" href="a04943.html#a5">bufferSize</a> = 100000</td></tr>
</table>
<hr><h2>Define Documentation</h2>
<a class="anchor" name="a1" doxytag="sha1.cpp::SHA1CircularShift" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> #define SHA1CircularShift</td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top">bits, <tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap>word </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap> (((word) << (bits)) | ((word) >> (32-(bits))))
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00235">235</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00430">SHA1ProcessMessageBlock()</a>. </td>
</tr>
</table>
<a class="anchor" name="a0" doxytag="sha1.cpp::SHA1HashSize" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> #define SHA1HashSize 20
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00106">106</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00299">SHA1Result()</a>. </td>
</tr>
</table>
<hr><h2>Typedef Documentation</h2>
<a class="anchor" name="a4" doxytag="sha1.cpp::int_least16_t" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> typedef short <a class="el" href="a04943.html#a4">int_least16_t</a>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00089">89</a> of file <a class="el" href="a06366.html">sha1.cpp</a>. </td>
</tr>
</table>
<a class="anchor" name="a7" doxytag="sha1.cpp::SHA1Context" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> typedef struct <a class="el" href="a03895.html">SHA1Context</a> <a class="el" href="a03895.html">SHA1Context</a>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
</td>
</tr>
</table>
<a class="anchor" name="a2" doxytag="sha1.cpp::uint32_t" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> typedef unsigned int <a class="el" href="a04943.html#a2">uint32_t</a>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00087">87</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00430">SHA1ProcessMessageBlock()</a>. </td>
</tr>
</table>
<a class="anchor" name="a3" doxytag="sha1.cpp::uint8_t" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> typedef unsigned char <a class="el" href="a04943.html#a3">uint8_t</a>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00088">88</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00139">getSHA1()</a>. </td>
</tr>
</table>
<hr><h2>Enumeration Type Documentation</h2>
<a class="anchor" name="a19" doxytag="sha1.cpp::@1" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> anonymous enum
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<dl compact><dt><b>Enumeration values: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em><a class="anchor" name="a19a8" doxytag="shaSuccess" ></a>shaSuccess</em> </td><td>
</td></tr>
<tr><td valign=top><em><a class="anchor" name="a19a9" doxytag="shaNull" ></a>shaNull</em> </td><td>
</td></tr>
<tr><td valign=top><em><a class="anchor" name="a19a10" doxytag="shaInputTooLong" ></a>shaInputTooLong</em> </td><td>
</td></tr>
<tr><td valign=top><em><a class="anchor" name="a19a11" doxytag="shaStateError" ></a>shaStateError</em> </td><td>
</td></tr>
</table>
</dl>
<p>
Definition at line <a class="el" href="a06366.html#l00098">98</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
<div class="fragment"><pre>00099 {
00100 <a class="code" href="a04943.html#a19a8">shaSuccess</a> = 0,
00101 <a class="code" href="a04943.html#a19a9">shaNull</a>, <span class="comment">/* Null pointer parameter */</span>
00102 <a class="code" href="a04943.html#a19a10">shaInputTooLong</a>, <span class="comment">/* input data too long */</span>
00103 <a class="code" href="a04943.html#a19a11">shaStateError</a> <span class="comment">/* called Input after Result */</span>
00104 };
</pre></div> </td>
</tr>
</table>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="a16" doxytag="sha1.cpp::getSHA1" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> <a class="el" href="a02607.html">CHashKey</a> getSHA1 </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top">const string & </td>
<td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00170">170</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a05646.html#l00649">buffer</a>, <a class="el" href="a06366.html#l00095">bufferSize</a>, <a class="el" href="a05708.html#l00255">NLMISC::CIFile::close()</a>, <a class="el" href="a05708.html#l00349">NLMISC::CIFile::eof()</a>, <a class="el" href="a05709.html#l00119">NLMISC::CIFile::getFileSize()</a>, <a class="el" href="a05484.html#l00038">min</a>, <a class="el" href="a05622.html#l00135">nlwarning</a>, <a class="el" href="a05708.html#l00135">NLMISC::CIFile::open()</a>, <a class="el" href="a05708.html#l00355">NLMISC::CIFile::serialBuffer()</a>, <a class="el" href="a05708.html#l00242">NLMISC::CIFile::setCacheFileOnOpen()</a>, <a class="el" href="a06366.html#l00357">SHA1Input()</a>, <a class="el" href="a06366.html#l00257">SHA1Reset()</a>, <a class="el" href="a06366.html#l00299">SHA1Result()</a>, <a class="el" href="a05981.html#l00104">sint</a>, <a class="el" href="a05981.html#l00096">uint8</a>, and <a class="el" href="a06366.html#l00088">uint8_t</a>.
<p>
<div class="fragment"><pre>00171 {
00172 <a class="code" href="a03895.html">SHA1Context</a> sha;
00173 <span class="keywordtype">int</span> err;
00174 <a class="code" href="a04943.html#a3">uint8_t</a> Message_Digest[20];
00175
00176 <span class="comment">//printf("reading '%s'\n", findData.cFileName);</span>
00177 <a class="code" href="a02653.html">CIFile</a> ifile;
00178 ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea20">setCacheFileOnOpen</a>(<span class="keyword">true</span>);
00179 <span class="keywordflow">if</span> (!ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea12">open</a>(CPath::lookup(filename)))
00180 {
00181 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"SHA: Can't open the file '%s'"</span>, <a class="code" href="a05377.html#a2">filename</a>.c_str());
00182 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00183 }
00184
00185 <span class="comment">//FILE *fp = fopen (filename.c_str(), "rb");</span>
00186 <span class="comment">//if (fp == NULL) return CHashKey();</span>
00187
00188 err = <a class="code" href="a04943.html#a12">SHA1Reset</a>(&sha);
00189 <span class="keywordflow">if</span> (err)
00190 {
00191 <a class="code" href="a04199.html#a2">nlwarning</a>(<span class="stringliteral">"SHA: SHA1Reset Error %d.\n"</span>, err );
00192 ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea3">close</a> ();
00193 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00194 }
00195
00196 <a class="code" href="a04558.html#a14">sint</a> fs = ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea6">getFileSize</a>();
00197 <a class="code" href="a04558.html#a14">sint</a> n, read = 0;
00198 <span class="keywordflow">do</span>
00199 {
00200 <span class="comment">//bs = (int)fread (buffer, 1, bufferSize, fp);</span>
00201 n = <a class="code" href="a04061.html#a0">std::min</a> (bufferSize, fs-read);
00202 <span class="comment">//nlinfo ("read %d bytes", n);</span>
00203 ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea15">serialBuffer</a>((<a class="code" href="a04558.html#a7">uint8</a> *)<a class="code" href="a04223.html#a589">buffer</a>, n);
00204
00205 err = <a class="code" href="a04943.html#a13">SHA1Input</a>(&sha, <a class="code" href="a04223.html#a589">buffer</a>, n);
00206 <span class="keywordflow">if</span> (err)
00207 {
00208 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"SHA: SHA1Input Error %d.\n"</span>, err);
00209 ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea3">close</a>();
00210 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00211 }
00212 read += n;
00213 }
00214 <span class="keywordflow">while</span> (!ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea4">eof</a>());
00215
00216 ifile.<a class="code" href="a02653.html#NLMISC_1_1CIFilea3">close</a> ();
00217
00218 err = <a class="code" href="a04943.html#a14">SHA1Result</a>(&sha, Message_Digest);
00219 <span class="keywordflow">if</span> (err)
00220 {
00221 <a class="code" href="a04199.html#a2">nlwarning</a>(<span class="stringliteral">"SHA: SHA1Result Error %d, could not compute message digest.\n"</span>, err );
00222 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00223 }
00224
00225 <a class="code" href="a02607.html">CHashKey</a> hk (Message_Digest);
00226 <span class="keywordflow">return</span> hk;
00227 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a15" doxytag="sha1.cpp::getSHA1" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> <a class="el" href="a02607.html">CHashKey</a> getSHA1 </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top">const <a class="el" href="a04558.html#a7">uint8</a> * </td>
<td class="mdname" nowrap> <em>buffer</em>, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap><a class="el" href="a04558.html#a11">uint32</a> </td>
<td class="mdname" nowrap> <em>size</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00139">139</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
<div class="fragment"><pre>00140 {
00141 <a class="code" href="a03895.html">SHA1Context</a> sha;
00142 <span class="keywordtype">int</span> err;
00143 <a class="code" href="a04943.html#a3">uint8_t</a> Message_Digest[20];
00144
00145 err = <a class="code" href="a04943.html#a12">SHA1Reset</a>(&sha);
00146 <span class="keywordflow">if</span> (err)
00147 {
00148 <a class="code" href="a04199.html#a2">nlwarning</a>(<span class="stringliteral">"SHA: SHA1Reset Error %d.\n"</span>, err );
00149 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00150 }
00151
00152 err = <a class="code" href="a04943.html#a13">SHA1Input</a>(&sha, (<span class="keyword">const</span> <a class="code" href="a04943.html#a3">uint8_t</a>*)buffer, size);
00153 <span class="keywordflow">if</span> (err)
00154 {
00155 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"SHA: SHA1Input Error %d.\n"</span>, err);
00156 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00157 }
00158
00159 err = <a class="code" href="a04943.html#a14">SHA1Result</a>(&sha, Message_Digest);
00160 <span class="keywordflow">if</span> (err)
00161 {
00162 <a class="code" href="a04199.html#a2">nlwarning</a>(<span class="stringliteral">"SHA: SHA1Result Error %d, could not compute message digest.\n"</span>, err );
00163 <span class="keywordflow">return</span> <a class="code" href="a02607.html">CHashKey</a>();
00164 }
00165
00166 <a class="code" href="a02607.html">CHashKey</a> hk (Message_Digest);
00167 <span class="keywordflow">return</span> hk;
00168 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a13" doxytag="sha1.cpp::SHA1Input" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int SHA1Input </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a03895.html">SHA1Context</a> * </td>
<td class="mdname" nowrap>, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap>const <a class="el" href="a04943.html#a3">uint8_t</a> * </td>
<td class="mdname" nowrap>, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap>unsigned </td>
<td class="mdname" nowrap> <em>int</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00357">357</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a06366.html#l00123">SHA1Context::Computed</a>, <a class="el" href="a06366.html#l00124">SHA1Context::Corrupted</a>, <a class="el" href="a06366.html#l00117">SHA1Context::Length_High</a>, <a class="el" href="a06366.html#l00116">SHA1Context::Length_Low</a>, <a class="el" href="a06366.html#l00121">SHA1Context::Message_Block</a>, <a class="el" href="a06366.html#l00120">SHA1Context::Message_Block_Index</a>, <a class="el" href="a06366.html#l00430">SHA1ProcessMessageBlock()</a>, <a class="el" href="a04943.html#a19a9">shaNull</a>, <a class="el" href="a04943.html#a19a11">shaStateError</a>, and <a class="el" href="a04943.html#a19a8">shaSuccess</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00139">getSHA1()</a>.
<p>
<div class="fragment"><pre>00360 {
00361 <span class="keywordflow">if</span> (!length)
00362 {
00363 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a8">shaSuccess</a>;
00364 }
00365
00366 <span class="keywordflow">if</span> (!context || !message_array)
00367 {
00368 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a9">shaNull</a>;
00369 }
00370
00371 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto0">Computed</a>)
00372 {
00373 context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a> = <a class="code" href="a04943.html#a19a11">shaStateError</a>;
00374
00375 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a11">shaStateError</a>;
00376 }
00377
00378 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a>)
00379 {
00380 <span class="keywordflow">return</span> context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a>;
00381 }
00382 <span class="keywordflow">while</span>(length-- && !context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a>)
00383 {
00384 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] =
00385 (*message_array & 0xFF);
00386
00387 context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> += 8;
00388 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> == 0)
00389 {
00390 context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a>++;
00391 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> == 0)
00392 {
00393 <span class="comment">/* Message is too long */</span>
00394 context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a> = 1;
00395 }
00396 }
00397
00398 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> == 64)
00399 {
00400 <a class="code" href="a04943.html#a18">SHA1ProcessMessageBlock</a>(context);
00401 }
00402
00403 message_array++;
00404 }
00405
00406 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a8">shaSuccess</a>;
00407 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a17" doxytag="sha1.cpp::SHA1PadMessage" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void SHA1PadMessage </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a03895.html">SHA1Context</a> * </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00541">541</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a06366.html#l00117">SHA1Context::Length_High</a>, <a class="el" href="a06366.html#l00116">SHA1Context::Length_Low</a>, <a class="el" href="a06366.html#l00121">SHA1Context::Message_Block</a>, <a class="el" href="a06366.html#l00120">SHA1Context::Message_Block_Index</a>, and <a class="el" href="a06366.html#l00430">SHA1ProcessMessageBlock()</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00299">SHA1Result()</a>.
<p>
<div class="fragment"><pre>00542 {
00543 <span class="comment">/*</span>
00544 <span class="comment"> * Check to see if the current message block is too small to hold</span>
00545 <span class="comment"> * the initial padding bits and length. If so, we will pad the</span>
00546 <span class="comment"> * block, process it, and then continue padding into a second</span>
00547 <span class="comment"> * block.</span>
00548 <span class="comment"> */</span>
00549 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> > 55)
00550 {
00551 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] = 0x80;
00552 <span class="keywordflow">while</span>(context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> < 64)
00553 {
00554 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] = 0;
00555 }
00556
00557 <a class="code" href="a04943.html#a18">SHA1ProcessMessageBlock</a>(context);
00558
00559 <span class="keywordflow">while</span>(context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> < 56)
00560 {
00561 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] = 0;
00562 }
00563 }
00564 <span class="keywordflow">else</span>
00565 {
00566 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] = 0x80;
00567 <span class="keywordflow">while</span>(context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> < 56)
00568 {
00569
00570 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a>++] = 0;
00571 }
00572 }
00573
00574 <span class="comment">/*</span>
00575 <span class="comment"> * Store the message length as the last 8 octets</span>
00576 <span class="comment"> */</span>
00577 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[56] = context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> >> 24;
00578 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[57] = context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> >> 16;
00579 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[58] = context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> >> 8;
00580 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[59] = context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a>;
00581 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[60] = context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> >> 24;
00582 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[61] = context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> >> 16;
00583 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[62] = context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> >> 8;
00584 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[63] = context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a>;
00585
00586 <a class="code" href="a04943.html#a18">SHA1ProcessMessageBlock</a>(context);
00587 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a18" doxytag="sha1.cpp::SHA1ProcessMessageBlock" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void SHA1ProcessMessageBlock </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a03895.html">SHA1Context</a> * </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00430">430</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a06366.html#l00114">SHA1Context::Intermediate_Hash</a>, <a class="el" href="a06366.html#l00121">SHA1Context::Message_Block</a>, <a class="el" href="a06366.html#l00120">SHA1Context::Message_Block_Index</a>, <a class="el" href="a06366.html#l00235">SHA1CircularShift</a>, <a class="el" href="a05646.html#l00985">t</a>, and <a class="el" href="a06366.html#l00087">uint32_t</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00357">SHA1Input()</a>, and <a class="el" href="a06366.html#l00541">SHA1PadMessage()</a>.
<p>
<div class="fragment"><pre>00431 {
00432 <span class="keyword">const</span> <a class="code" href="a04943.html#a2">uint32_t</a> K[] = { <span class="comment">/* Constants defined in SHA-1 */</span>
00433 0x5A827999,
00434 0x6ED9EBA1,
00435 0x8F1BBCDC,
00436 0xCA62C1D6
00437 };
00438 <span class="keywordtype">int</span> <a class="code" href="a04223.html#a627">t</a>; <span class="comment">/* Loop counter */</span>
00439 <a class="code" href="a04943.html#a2">uint32_t</a> temp; <span class="comment">/* Temporary word value */</span>
00440 <a class="code" href="a04943.html#a2">uint32_t</a> W[80]; <span class="comment">/* Word sequence */</span>
00441 <a class="code" href="a04943.html#a2">uint32_t</a> A, B, C, D, E; <span class="comment">/* Word buffers */</span>
00442
00443 <span class="comment">/*</span>
00444 <span class="comment"> * Initialize the first 16 words in the array W</span>
00445 <span class="comment"> */</span>
00446 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 0; <a class="code" href="a04223.html#a627">t</a> < 16; <a class="code" href="a04223.html#a627">t</a>++)
00447 {
00448 W[<a class="code" href="a04223.html#a627">t</a>] = context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[<a class="code" href="a04223.html#a627">t</a> * 4] << 24;
00449 W[<a class="code" href="a04223.html#a627">t</a>] |= context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[<a class="code" href="a04223.html#a627">t</a> * 4 + 1] << 16;
00450 W[<a class="code" href="a04223.html#a627">t</a>] |= context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[<a class="code" href="a04223.html#a627">t</a> * 4 + 2] << 8;
00451 W[<a class="code" href="a04223.html#a627">t</a>] |= context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[<a class="code" href="a04223.html#a627">t</a> * 4 + 3];
00452 }
00453
00454 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 16; <a class="code" href="a04223.html#a627">t</a> < 80; <a class="code" href="a04223.html#a627">t</a>++)
00455 {
00456 W[<a class="code" href="a04223.html#a627">t</a>] = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
00457 }
00458
00459 A = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[0];
00460 B = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[1];
00461 C = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[2];
00462 D = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[3];
00463 E = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[4];
00464
00465 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 0; <a class="code" href="a04223.html#a627">t</a> < 20; <a class="code" href="a04223.html#a627">t</a>++)
00466 {
00467 temp = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(5,A) +
00468 ((B & C) | ((~B) & D)) + E + W[<a class="code" href="a04223.html#a627">t</a>] + K[0];
00469 E = D;
00470 D = C;
00471 C = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(30,B);
00472
00473 B = A;
00474 A = temp;
00475 }
00476
00477 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 20; <a class="code" href="a04223.html#a627">t</a> < 40; <a class="code" href="a04223.html#a627">t</a>++)
00478 {
00479 temp = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(5,A) + (B ^ C ^ D) + E + W[<a class="code" href="a04223.html#a627">t</a>] + K[1];
00480 E = D;
00481 D = C;
00482 C = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(30,B);
00483 B = A;
00484 A = temp;
00485 }
00486
00487 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 40; <a class="code" href="a04223.html#a627">t</a> < 60; <a class="code" href="a04223.html#a627">t</a>++)
00488 {
00489 temp = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(5,A) +
00490 ((B & C) | (B & D) | (C & D)) + E + W[<a class="code" href="a04223.html#a627">t</a>] + K[2];
00491 E = D;
00492 D = C;
00493 C = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(30,B);
00494 B = A;
00495 A = temp;
00496 }
00497
00498 <span class="keywordflow">for</span>(<a class="code" href="a04223.html#a627">t</a> = 60; <a class="code" href="a04223.html#a627">t</a> < 80; <a class="code" href="a04223.html#a627">t</a>++)
00499 {
00500 temp = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(5,A) + (B ^ C ^ D) + E + W[<a class="code" href="a04223.html#a627">t</a>] + K[3];
00501 E = D;
00502 D = C;
00503 C = <a class="code" href="a04943.html#a1">SHA1CircularShift</a>(30,B);
00504 B = A;
00505 A = temp;
00506 }
00507
00508 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[0] += A;
00509 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[1] += B;
00510 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[2] += C;
00511 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[3] += D;
00512 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[4] += E;
00513
00514 context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> = 0;
00515 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a12" doxytag="sha1.cpp::SHA1Reset" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int SHA1Reset </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a03895.html">SHA1Context</a> * </td>
<td class="mdname1" valign="top" nowrap> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00257">257</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a06366.html#l00123">SHA1Context::Computed</a>, <a class="el" href="a06366.html#l00124">SHA1Context::Corrupted</a>, <a class="el" href="a06366.html#l00114">SHA1Context::Intermediate_Hash</a>, <a class="el" href="a06366.html#l00117">SHA1Context::Length_High</a>, <a class="el" href="a06366.html#l00116">SHA1Context::Length_Low</a>, <a class="el" href="a06366.html#l00120">SHA1Context::Message_Block_Index</a>, <a class="el" href="a04943.html#a19a9">shaNull</a>, and <a class="el" href="a04943.html#a19a8">shaSuccess</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00139">getSHA1()</a>.
<p>
<div class="fragment"><pre>00258 {
00259 <span class="keywordflow">if</span> (!context)
00260 {
00261 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a9">shaNull</a>;
00262 }
00263
00264 context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> = 0;
00265 context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> = 0;
00266 context-><a class="code" href="a03895.html#SHA1Contexto6">Message_Block_Index</a> = 0;
00267
00268 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[0] = 0x67452301;
00269 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[1] = 0xEFCDAB89;
00270 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[2] = 0x98BADCFE;
00271 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[3] = 0x10325476;
00272 context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[4] = 0xC3D2E1F0;
00273
00274 context-><a class="code" href="a03895.html#SHA1Contexto0">Computed</a> = 0;
00275 context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a> = 0;
00276
00277 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a8">shaSuccess</a>;
00278 }
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="a14" doxytag="sha1.cpp::SHA1Result" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int SHA1Result </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="a03895.html">SHA1Context</a> * </td>
<td class="mdname" nowrap>, </td>
</tr>
<tr>
<td class="md" nowrap align="right"></td>
<td></td>
<td class="md" nowrap><a class="el" href="a04943.html#a3">uint8_t</a> </td>
<td class="mdname" nowrap> <em>Message_Digest</em>[20]</td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00299">299</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
References <a class="el" href="a06366.html#l00123">SHA1Context::Computed</a>, <a class="el" href="a06366.html#l00124">SHA1Context::Corrupted</a>, <a class="el" href="a06366.html#l00114">SHA1Context::Intermediate_Hash</a>, <a class="el" href="a06366.html#l00117">SHA1Context::Length_High</a>, <a class="el" href="a06366.html#l00116">SHA1Context::Length_Low</a>, <a class="el" href="a06366.html#l00121">SHA1Context::Message_Block</a>, <a class="el" href="a06366.html#l00106">SHA1HashSize</a>, <a class="el" href="a06366.html#l00541">SHA1PadMessage()</a>, <a class="el" href="a04943.html#a19a9">shaNull</a>, and <a class="el" href="a04943.html#a19a8">shaSuccess</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00139">getSHA1()</a>.
<p>
<div class="fragment"><pre>00301 {
00302 <span class="keywordtype">int</span> i;
00303
00304 <span class="keywordflow">if</span> (!context || !Message_Digest)
00305 {
00306 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a9">shaNull</a>;
00307 }
00308
00309 <span class="keywordflow">if</span> (context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a>)
00310 {
00311 <span class="keywordflow">return</span> context-><a class="code" href="a03895.html#SHA1Contexto1">Corrupted</a>;
00312 }
00313
00314 <span class="keywordflow">if</span> (!context-><a class="code" href="a03895.html#SHA1Contexto0">Computed</a>)
00315 {
00316 <a class="code" href="a04943.html#a17">SHA1PadMessage</a>(context);
00317 <span class="keywordflow">for</span>(i=0; i<64; ++i)
00318 {
00319 <span class="comment">/* message may be sensitive, clear it out */</span>
00320 context-><a class="code" href="a03895.html#SHA1Contexto5">Message_Block</a>[i] = 0;
00321 }
00322 context-><a class="code" href="a03895.html#SHA1Contexto4">Length_Low</a> = 0; <span class="comment">/* and clear length */</span>
00323 context-><a class="code" href="a03895.html#SHA1Contexto3">Length_High</a> = 0;
00324 context-><a class="code" href="a03895.html#SHA1Contexto0">Computed</a> = 1;
00325
00326 }
00327
00328 <span class="keywordflow">for</span>(i = 0; i < <a class="code" href="a04943.html#a0">SHA1HashSize</a>; ++i)
00329 {
00330 Message_Digest[i] = context-><a class="code" href="a03895.html#SHA1Contexto2">Intermediate_Hash</a>[i>>2]
00331 >> 8 * ( 3 - ( i & 0x03 ) );
00332 }
00333
00334 <span class="keywordflow">return</span> <a class="code" href="a04943.html#a19a8">shaSuccess</a>;
00335 }
</pre></div> </td>
</tr>
</table>
<hr><h2>Variable Documentation</h2>
<a class="anchor" name="a6" doxytag="sha1.cpp::buffer" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> <a class="el" href="a04943.html#a3">uint8_t</a> <a class="el" href="a04223.html#a589">buffer</a>[<a class="el" href="a04943.html#a5">bufferSize</a>]<code> [static]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00096">96</a> of file <a class="el" href="a06366.html">sha1.cpp</a>. </td>
</tr>
</table>
<a class="anchor" name="a5" doxytag="sha1.cpp::bufferSize" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> const int <a class="el" href="a04943.html#a5">bufferSize</a> = 100000<code> [static]</code>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="a06366.html#l00095">95</a> of file <a class="el" href="a06366.html">sha1.cpp</a>.
<p>
Referenced by <a class="el" href="a06366.html#l00170">getSHA1()</a>. </td>
</tr>
</table>
<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 06:43:17 2004 for NeL by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
</a>1.3.6 </small></address>
</body>
</html>
|