C++ how to make simple sha256 generator with boost?
I need a simple string to sha256 generator class. I do not want to build big libraries for that like openSSL or Cripto开发者_StackOverflow社区++ - all I want is to turn strings into sha256. How to create such class or where to get it?
Like others have said, I was under the impression that hashing under SHA256 is not trivial enough to simply implement yourself as a subset of a bigger coding project. If you take a look at the wikipedia page for SHA-2, you will notice some pretty intense math. If you would like the actual encryption abstract (the math theory itself), it can be found here. If you're like most programmers whose emphasis is not in security, then you will probably want to simply use someone else's tested and tried implementation. You can find a good few here. Let me know if this helped. Sorry I couldn't answer your question with straight code or something of that nature.
You find C source code directly in the section 8 of RFC 6234. Make sure you check the errata also.
you want this?
static void
sha2_round(const unsigned char *data, sph_u32 r[8])
{
int i;
sph_u32 a, b, c, d, e, f, g, h;
sph_u32 w[64];
for (i = 0; i < 16; i ++)
w[i] = sph_dec32be_aligned(data + (4 * i));
for (i = 16; i < 64; i ++) {
w[i] = SPH_T32(SSG2_1(w[i - 2]) + w[i - 7]
+ SSG2_0(w[i - 15]) + w[i - 16]);
go to http://www.saphir2.com/sphlib/ and download it. it's under the GPL. look in sha2.c
beware, it doesn't have a lot of documentation. it's set up for people who already know what they're doing.
GNU coreutils has a very simple source code. just download coreutils, they even have a test suite you can build, and the source code is full of comments and docs.
精彩评论