| 156 | } |
| 157 | |
| 158 | static void sha_done(sha256_state *md, void *out) |
| 159 | { |
| 160 | int i; |
| 161 | |
| 162 | // Increase the length of the message |
| 163 | md->length += md->curlen * 8; |
| 164 | |
| 165 | // Append the '1' bit |
| 166 | md->buf[md->curlen++] = (unsigned char)0x80; |
| 167 | |
| 168 | // If the length is currently above 56 bytes we append zeros then compress. |
| 169 | // Then we can fall back to padding zeros and length encoding like normal. |
| 170 | if(md->curlen > 56) |
| 171 | { |
| 172 | while(md->curlen < 64) |
| 173 | md->buf[md->curlen++] = 0; |
| 174 | sha_compress(md, md->buf); |
| 175 | md->curlen = 0; |
| 176 | } |
| 177 | |
| 178 | // Pad up to 56 bytes of zeroes |
| 179 | while(md->curlen < 56) |
| 180 | md->buf[md->curlen++] = 0; |
| 181 | |
| 182 | // Store length |
| 183 | store64(md->length, md->buf + 56); |
| 184 | sha_compress(md, md->buf); |
| 185 | |
| 186 | // Copy output |
| 187 | for(i = 0; i < 8; i++) |
| 188 | store32(md->state[i], (unsigned char *)out + (4 * i)); |
| 189 | } |
| 190 | |
| 191 | void sha256_init(SHA256_CTX *ctxt) |
| 192 | { |
no test coverage detected