]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/sha2.cc
dcdbef6e757a7877c7b00652ec10b86b77be8a03
2 * Cryptographic API. {{{
4 * SHA-512, as specified in
5 * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
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)
15 #pragma implementation "apt-pkg/sha2.h"
18 #include <apt-pkg/sha2.h>
19 #include <apt-pkg/strutl.h>
24 SHA512Summation::SHA512Summation() /*{{{*/
31 SHA512SumValue
SHA512Summation::Result() /*{{{*/
34 SHA512_Final(Sum
, &ctx
);
43 bool SHA512Summation::Add(const unsigned char *inbuf
,unsigned long len
) /*{{{*/
47 SHA512_Update(&ctx
, inbuf
, len
);
51 // SHA512Summation::AddFD - Add content of file into the checksum /*{{{*/
52 // ---------------------------------------------------------------------
54 bool SHA512Summation::AddFD(int Fd
,unsigned long Size
)
56 unsigned char Buf
[64 * 64];
58 int ToEOF
= (Size
== 0);
59 while (Size
!= 0 || ToEOF
)
61 unsigned n
= sizeof(Buf
);
62 if (!ToEOF
) n
= min(Size
,(unsigned long)n
);
64 if (Res
< 0 || (!ToEOF
&& (unsigned) Res
!= n
)) // error, or short read
66 if (ToEOF
&& Res
== 0) // EOF
75 SHA256Summation::SHA256Summation() /*{{{*/
81 bool SHA256Summation::Add(const unsigned char *inbuf
,unsigned long len
) /*{{{*/
85 SHA256_Update(&ctx
, inbuf
, len
);
89 SHA256SumValue
SHA256Summation::Result() /*{{{*/
92 SHA256_Final(Sum
, &ctx
);
101 // SHA256Summation::AddFD - Add content of file into the checksum /*{{{*/
102 // ---------------------------------------------------------------------
104 bool SHA256Summation::AddFD(int Fd
,unsigned long Size
)
106 unsigned char Buf
[64 * 64];
108 int ToEOF
= (Size
== 0);
109 while (Size
!= 0 || ToEOF
)
111 unsigned n
= sizeof(Buf
);
112 if (!ToEOF
) n
= min(Size
,(unsigned long)n
);
113 Res
= read(Fd
,Buf
,n
);
114 if (Res
< 0 || (!ToEOF
&& (unsigned) Res
!= n
)) // error, or short read
116 if (ToEOF
&& Res
== 0) // EOF