]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/sha2.cc
merge with debian-experimental
[apt.git] / apt-pkg / contrib / sha2.cc
1 /*
2 * Cryptographic API. {{{
3 *
4 * SHA-512, as specified in
5 * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 */ /*}}}*/
13
14 #ifdef __GNUG__
15 #pragma implementation "apt-pkg/sha2.h"
16 #endif
17
18 #include <apt-pkg/sha2.h>
19 #include <apt-pkg/strutl.h>
20
21 // SHA2Summation::AddFD - Add content of file into the checksum /*{{{*/
22 // ---------------------------------------------------------------------
23 /* */
24 bool SHA2SummationBase::AddFD(int Fd,unsigned long Size){
25 unsigned char Buf[64 * 64];
26 int Res = 0;
27 int ToEOF = (Size == 0);
28 while (Size != 0 || ToEOF)
29 {
30 unsigned n = sizeof(Buf);
31 if (!ToEOF) n = min(Size,(unsigned long)n);
32 Res = read(Fd,Buf,n);
33 if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
34 return false;
35 if (ToEOF && Res == 0) // EOF
36 break;
37 Size -= Res;
38 Add(Buf,Res);
39 }
40 return true;
41 }
42 /*}}}*/
43