Skip to content

Instantly share code, notes, and snippets.



Last active Sep 30, 2019
What would you like to do?
a strncat tests
* strncat test
* build: gcc -o strncpy strncpy.c -lcrypto
* output:
* $ ./strncpy
* time: 1569841068 sha256(long): H8Zw/CnxF9d/kG10Ck7VfDMNqWADDGMsrD7Wx0wTshY=
* sha256(short): H8Zw/CnxF9d/
* time: 1569841069 sha256(long): uyzMNURXeyOjyCZ1ANI6Lze6lwF1bKUPjU3rHBZyTNY=
* sha256(short): H8Zw/CnxF9d/uyzMNURXeyOj
* time: 1569841070 sha256(long): 1zdqJgOCuILZkti92I2YUuT/KGNuqmSPOioA8rjxEeg=
* sha256(short): H8Zw/CnxF9d/uyzM1zdqJgOCuILZkti92I2YUuT/KGNuqmSPOioA8rjxEeg=1zdqJgOCuILZ
* time: 1569841071 sha256(long): Bvf5PF9cd0q01tccsNNvNtDjPMgUSWbMx2rNgLVFgEo=
* sha256(short): H8Zw/CnxF9d/uyzMBvf5PF9cd0q01tccsNNvNtDjPMgUSWbMx2rNgLVFgEo=Bvf5PF9cd0q0
* time: 1569841072 sha256(long): S/06FjYG/uc3FxAY/DQbEIxezMw+xGfEbg0i373utQs=
* sha256(short): H8Zw/CnxF9d/uyzMS/06FjYG/uc3FxAY/DQbEIxezMw+xGfEbg0i373utQs=S/06FjYG/uc3
* time: 1569841073 sha256(long): miGQZLfdfwozwdkunw1RUA+v+eqlx6DjO7hryjuIcQc=
* sha256(short): H8Zw/CnxF9d/uyzMmiGQZLfdfwozwdkunw1RUA+v+eqlx6DjO7hryjuIcQc=miGQZLfdfwoz
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
int main(int argc, char *argv[]) {
char base64[64], buf[16];
unsigned char hash[SHA256_DIGEST_LENGTH] = {0};
time_t tim;
SHA256_CTX ctx;
while (true) {
tim = time(NULL);
SHA256_Update(&ctx, &tim, sizeof(tim));
SHA256_Final(hash, &ctx);
EVP_EncodeBlock(base64, hash, SHA256_DIGEST_LENGTH);
printf("time: %ld sha256(long): %s\n", tim, base64);
strncat(buf, base64, 12);
printf("sha256(short): %s\n", buf);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.