Ejemplo n.º 1
0
/* 
 * Generate an MD5 cancel lock.
 */
unsigned char *
 md5_lock(char *secret, int seclen, char *message, int msglen)
{
    unsigned char *cankey, *canlock;
    unsigned char hmacbuff[MD5_LENGTH];
    unsigned char junk[MD5_LENGTH];
    MD5_CTX hash_ctx;

    cankey = lock_strip_alpha(md5_key(secret, seclen, message, msglen), junk);

    canlock = (char *) malloc(BUFFSIZE);
    MD5Init(&hash_ctx);
    MD5Update(&hash_ctx, cankey, strlen(cankey));
    MD5Final(hmacbuff, &hash_ctx);
    strcpy(canlock, "md5:");
    (void) b64_ntop(hmacbuff, MD5_LENGTH, canlock + 4, BUFFSIZE);

    return (canlock);
}
Ejemplo n.º 2
0
void create_encrypted_file(char *username, char *objname, char *passphrase){
  char filename[strlen(OBJECT_DIR) + strlen(username) + strlen(CONCAT) + strlen(objname) + 1];
  char buffer[BUFFERSIZE];
  char *plaintext;
  unsigned char *iv = create_init_vector();
  unsigned char *key = md5_key(passphrase, strlen(passphrase));

  snprintf(filename, sizeof(filename), "%s%s%s%s", OBJECT_DIR, username, CONCAT, objname);
  plaintext = calloc(1,1);

  // Get plaintext
  while (fgets(buffer, BUFFERSIZE, stdin) != NULL){
    plaintext = realloc(plaintext, strlen(plaintext) + 1 + strlen(buffer));
    if (!plaintext) { printf("[Objput ERROR]: fail to read input \n"); exit(-1); }
    strcat(plaintext, buffer);
  }

  // Write encrypted file
  Crypto crypto = write_encrypted_file(filename, plaintext, key, iv);
  // Save encryption key in a file
  save_encryption_key(username, objname, crypto.text_len, passphrase, iv);

  printf("[Objput SUCCESS] File %s created. \n", filename);
}