Initial commit
[keepassx] / src / crypto / sha256.h
1 /***************************************************************************
2  *   Copyright (C) 2001-2003 by Christophe Devine                          *
3  *   Copyright (C) 2005-2006 by Tarek Saidi                                *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _SHA256_H
22 #define _SHA256_H
23
24 #include <QGlobalStatic>
25
26 typedef struct
27 {
28     quint32 total[2];
29     quint32 state[8];
30     quint8 buffer[64];
31 }sha256_context;
32
33 extern void sha256_starts( sha256_context *ctx );
34 extern void sha256_update( sha256_context *ctx, const quint8 *input, quint32 length );
35 extern void sha256_finish( sha256_context *ctx, quint8 digest[32] );
36
37 class SHA256{
38         public:
39                 SHA256(){sha256_starts(&ctx);}
40                 ~SHA256(){overwriteCtx(&ctx);};
41                 void update(void* input,quint32 length){sha256_update(&ctx,(quint8*)input,length);}
42                 void finish(void* digest){sha256_finish(&ctx,(quint8*)digest);}
43                 static void hashBuffer(const void* input, void* digest,quint32 length);
44         private:
45                 static void overwriteCtx(sha256_context* ctx);
46                 sha256_context ctx;
47 };
48
49
50 #endif /* sha256.h */