sha256.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 23 Jun 2017 17:28:03 -0400
changeset 58 1390348facc7
parent 46 fe4f59680246
permissions -rw-r--r--
Command line tool that decrypts an OPVault keychain and dumps it to stdout.

To compile: gcc -o opvault opvault.c cJSON.c -lcrypto

Usage: ./opvault </path/to/mykeychain.opvault> <password>

This is just a proof of concept; I'll be recycling this into proper OPVault
support in 1pass later and deleting this tool.

This uses OpenSSL's libcrypto for the math instead of all the homegrown
crypto this project is otherwise using. I'll probably migrate the rest in
this direction, too, since this wasn't as bad as I expected to use and
gets you all the package-manager mojo of automatic bug fixes and security
patches and shared code, etc.

cJSON parses JSON in C. That is from https://github.com/DaveGamble/cJSON

An example OPVault keychain from AgileBits is available here:

https://cache.agilebits.com/security-kb/
icculus@46
     1
/*********************************************************************
icculus@46
     2
* Filename:   sha256.h
icculus@46
     3
* Author:     Brad Conte (brad AT bradconte.com)
icculus@46
     4
* Copyright:
icculus@46
     5
* Disclaimer: This code is presented "as is" without any guarantees.
icculus@46
     6
* Details:    Defines the API for the corresponding SHA1 implementation.
icculus@46
     7
*********************************************************************/
icculus@46
     8
icculus@46
     9
#ifndef SHA256_H
icculus@46
    10
#define SHA256_H
icculus@46
    11
icculus@46
    12
/*************************** HEADER FILES ***************************/
icculus@46
    13
#include <stddef.h>
icculus@46
    14
icculus@46
    15
/****************************** MACROS ******************************/
icculus@46
    16
#define SHA256_BLOCK_SIZE 32            // SHA256 outputs a 32 byte digest
icculus@46
    17
icculus@46
    18
/**************************** DATA TYPES ****************************/
icculus@46
    19
typedef unsigned char BYTE;             // 8-bit byte
icculus@46
    20
typedef unsigned int  WORD;             // 32-bit word, change to "long" for 16-bit machines
icculus@46
    21
icculus@46
    22
typedef struct {
icculus@46
    23
	BYTE data[64];
icculus@46
    24
	WORD datalen;
icculus@46
    25
	unsigned long long bitlen;
icculus@46
    26
	WORD state[8];
icculus@46
    27
} SHA256_CTX;
icculus@46
    28
icculus@46
    29
/*********************** FUNCTION DECLARATIONS **********************/
icculus@46
    30
void sha256_init(SHA256_CTX *ctx);
icculus@46
    31
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
icculus@46
    32
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
icculus@46
    33
icculus@46
    34
#endif   // SHA256_H