mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 06:55:52 +08:00
Initial commit
This commit is contained in:
77
SHA256.h
Normal file
77
SHA256.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2011,2015 by Jonathan Naylor G4KLX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef SHA256_H
|
||||
#define SHA256_H
|
||||
|
||||
#if defined(WIN32)
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
#include <cstdint>
|
||||
#endif
|
||||
|
||||
enum {
|
||||
SHA256_DIGEST_SIZE = 256 / 8
|
||||
};
|
||||
|
||||
class CSHA256 {
|
||||
public:
|
||||
CSHA256();
|
||||
~CSHA256();
|
||||
|
||||
/* Starting with the result of former calls of this function (or the
|
||||
initialization function update the context for the next LEN bytes
|
||||
starting at BUFFER.
|
||||
It is necessary that LEN is a multiple of 64!!! */
|
||||
void processBlock(const unsigned char* buffer, unsigned int len);
|
||||
|
||||
/* Starting with the result of former calls of this function (or the
|
||||
initialization function update the context for the next LEN bytes
|
||||
starting at BUFFER.
|
||||
It is NOT required that LEN is a multiple of 64. */
|
||||
void processBytes(const unsigned char* buffer, unsigned int len);
|
||||
|
||||
/* Process the remaining bytes in the buffer and put result from CTX
|
||||
in first 32 bytes following RESBUF. The result is always in little
|
||||
endian byte order, so that a byte-wise output yields to the wanted
|
||||
ASCII representation of the message digest. */
|
||||
unsigned char* finish(unsigned char* resbuf);
|
||||
|
||||
/* Put result from CTX in first 32 bytes following RESBUF. The result is
|
||||
always in little endian byte order, so that a byte-wise output yields
|
||||
to the wanted ASCII representation of the message digest. */
|
||||
unsigned char* read(unsigned char* resbuf);
|
||||
|
||||
/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The
|
||||
result is always in little endian byte order, so that a byte-wise
|
||||
output yields to the wanted ASCII representation of the message
|
||||
digest. */
|
||||
unsigned char* buffer(const unsigned char* buffer, unsigned int len, unsigned char* resblock);
|
||||
|
||||
private:
|
||||
uint32_t* m_state;
|
||||
uint32_t* m_total;
|
||||
unsigned int m_buflen;
|
||||
uint32_t* m_buffer;
|
||||
|
||||
void init();
|
||||
void conclude();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user