changed all occurrences of unsigned char to byte (defined in defines.h) to make the code more precise about sizes.

This commit is contained in:
git@daemon.de
2014-02-25 11:09:58 +01:00
parent cbc45f5fa1
commit 3b1db06529
31 changed files with 243 additions and 240 deletions

View File

@@ -283,7 +283,7 @@ int buffer_done(Buffer *b);
Then the following code would:
@code
unsigned char g[4];
byte g[4];
buffer_get_chunk(b, g, 4); // => g now contains 'AAAA'
buffer_get_chunk(b, g, 4); // => g now contains 'BBBB'
buffer_get_chunk(b, g, 4); // => g now contains 'CCCC'
@@ -316,7 +316,7 @@ size_t buffer_get_chunk(Buffer *b, void *buf, size_t len);
\return Pointer to the buffer data storage.
*/
unsigned char *buffer_get(Buffer *b);
byte *buffer_get(Buffer *b);
/** Read the whole Buffer content as string.
@@ -365,8 +365,8 @@ char *buffer_get_str(Buffer *b);
@code
[..]
unsigned char g[4];
unsigned char *r = NULL;
byte g[4];
byte *r = NULL;
buffer_get_chunk(b, g, 4); // => g now contains 'AAAA'
size_t rs = buffer_left(b); // => rs = 8
r = buffer_get_remainder(b); // => r now contains 'BBBBCCCC' and has a size of 8
@@ -378,7 +378,7 @@ char *buffer_get_str(Buffer *b);
\return Pointer to the remaining chunk of data (copy).
*/
unsigned char *buffer_get_remainder(Buffer *b);
byte *buffer_get_remainder(Buffer *b);
/** Read some data inside the Buffer.
@@ -399,7 +399,7 @@ unsigned char *buffer_get_remainder(Buffer *b);
Then:
@code
[..]
unsigned char g[4];
byte g[4];
buffer_extract(b, g, 4, 4); // => g now contains 'BBBB'
@endcode
@@ -455,8 +455,8 @@ size_t buffer_size(const Buffer *b);
Then:
@code
[..]
unsigned char g[4];
unsigned char x[16];
byte g[4];
byte x[16];
buffer_get_chunk(b, g, 4); // => g now contains 'BBBB'
if(buffer_left(b) >= 16) // => will return 8 and therefore fail
buffer_get_chunk(b, x, 16);

View File

@@ -115,16 +115,16 @@
of 32k, N is a nonce (new per block) and S the symmetric key.
*/
size_t pcp_sodium_box(unsigned char **cipher,
unsigned char *cleartext,
size_t pcp_sodium_box(byte **cipher,
byte *cleartext,
size_t clearsize,
unsigned char *nonce,
unsigned char *secret,
unsigned char *pub);
byte *nonce,
byte *secret,
byte *pub);
int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
size_t messagesize, unsigned char *nonce,
unsigned char *secret, unsigned char *pub);
int pcp_sodium_verify_box(byte **cleartext, byte* message,
size_t messagesize, byte *nonce,
byte *secret, byte *pub);
/** Asymmetrically encrypt a message.
@@ -143,11 +143,11 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
\param[out] csize A pointer which will be set to the size of the encrypted result if successful.
\return Returns an allocated unsigned char array of the size csize which contains the encrypted result.
\return Returns an allocated byte array of the size csize which contains the encrypted result.
In case of an error, it returns NULL sets csize to 0. Use fatals_ifany() to check for errors.
*/
unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
unsigned char *message, size_t messagesize,
byte *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
byte *message, size_t messagesize,
size_t *csize);
/** Asymmetrically decrypt a message.
@@ -167,11 +167,11 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
\param[out] dsize A pointer which will be set to the size of the decrypted result if successful.
\return Returns an allocated unsigned char array of the size csize which contains the encrypted result.
\return Returns an allocated byte array of the size csize which contains the encrypted result.
In case of an error, it returns NULL sets csize to 0. Use fatals_ifany() to check for errors.
*/
unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
unsigned char *cipher, size_t ciphersize,
byte *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
byte *cipher, size_t ciphersize,
size_t *dsize);
@@ -217,7 +217,7 @@ size_t pcp_encrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, pcp_pubke
\return Returns the size of the output written to the output stream or 0 in case of errors.
*/
size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symkey, int havehead, pcp_rec_t *recsign);
size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, byte *symkey, int havehead, pcp_rec_t *recsign);
/** Asymmetrically decrypt a file or a buffer stream.
@@ -241,7 +241,7 @@ size_t pcp_encrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symk
\return Returns the size of the output written to the output stream or 0 in case of errors.
*/
size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned char *symkey, int verify);
size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, byte *symkey, int verify);
/** Symmetrically decrypt a file or a buffer stream.
@@ -263,9 +263,9 @@ size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, unsigned
\return Returns the size of the output written to the output stream or 0 in case of errors.
*/
size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, unsigned char *symkey, pcp_rec_t *recverify);
size_t pcp_decrypt_stream_sym(Pcpstream *in, Pcpstream* out, byte *symkey, pcp_rec_t *recverify);
pcp_rec_t *pcp_rec_new(unsigned char *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub);
pcp_rec_t *pcp_rec_new(byte *cipher, size_t clen, pcp_key_t *secret, pcp_pubkey_t *pub);
void pcp_rec_free(pcp_rec_t *r);
#endif /* _HAVE_PCP_CRYPTO_H */

View File

@@ -56,7 +56,7 @@
\return Returns message+signature with size of messagesize + crypto_sign_BYTES,
or NULL in case of an error.
*/
unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s);
byte *pcp_ed_sign(byte *message, size_t messagesize, pcp_key_t *s);
/** Sign a raw message using s->mastersecret.
@@ -72,7 +72,7 @@ unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t
\return Returns message+signature with size of messagesize + crypto_sign_BYTES,
or NULL in case of an error.
*/unsigned char *pcp_ed_sign_key(unsigned char *message, size_t messagesize, pcp_key_t *s);
*/byte *pcp_ed_sign_key(byte *message, size_t messagesize, pcp_key_t *s);
/** Verify a signature.
@@ -89,7 +89,7 @@ unsigned char *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t
\return If the signature verifies return the raw message with the signature removed (size: siglen - crypto_sign_BYTES),
returns NULL in case of errors. Check fatals_if_any().
*/
unsigned char *pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey_t *p);
byte *pcp_ed_verify(byte *signature, size_t siglen, pcp_pubkey_t *p);
/** Verify a signature using the mastersecret.
@@ -106,7 +106,7 @@ unsigned char *pcp_ed_verify(unsigned char *signature, size_t siglen, pcp_pubkey
\return If the signature verifies return the raw message with the signature removed (size: siglen - crypto_sign_BYTES),
returns NULL in case of errors. Check fatals_if_any().
*/
unsigned char *pcp_ed_verify_key(unsigned char *signature, size_t siglen, pcp_pubkey_t *p);
byte *pcp_ed_verify_key(byte *signature, size_t siglen, pcp_pubkey_t *p);
/** Sign a stream in 32k block mode.

View File

@@ -342,9 +342,9 @@ char *pcp_getpubkeyid(pcp_pubkey_t *k);
\param[in] k The public key structure.
\return Returns a pointer to an 32 byte unsigned char.
\return Returns a pointer to an 32 byte byte.
*/
unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k);
byte *pcppubkey_getchecksum(pcp_pubkey_t *k);
/** Calculate a checksum of a public key part of the given secret key.
@@ -352,9 +352,9 @@ unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k);
\param[in] k The secret key structure.
\return Returns a pointer to an 32 byte unsigned char.
\return Returns a pointer to an 32 byte byte.
*/
unsigned char *pcpkey_getchecksum(pcp_key_t *k);
byte *pcpkey_getchecksum(pcp_key_t *k);
/** Checks if a secret key structure is registered in the secret key hash.
@@ -396,14 +396,14 @@ pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k);
functions. It allocates the memory and the caller is responsible
to clear and free() it after use.
\return Returns a pointer to a 24 byte unsigned char array.
\return Returns a pointer to a 24 byte byte array.
*/
unsigned char * pcp_gennonce();
byte * pcp_gennonce();
/* use scrypt() to create a key from a passphrase and a nonce
FIXME: use pure scrypt() instead.
*/
unsigned char *pcp_derivekey(char *passphrase, unsigned char *nonce);
byte *pcp_derivekey(char *passphrase, byte *nonce);
/* FIXME: abandon and use Buffer instead */
void pcp_seckeyblob(void *blob, pcp_key_t *k);

View File

@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <errno.h>
#include <sodium.h>
#include "defines.h"
#include "pad.h"
#include "mem.h"
@@ -55,11 +56,11 @@
\return Returns the size of \a cipher.
*/
size_t pcp_sodium_mac(unsigned char **cipher,
unsigned char *cleartext,
size_t pcp_sodium_mac(byte **cipher,
byte *cleartext,
size_t clearsize,
unsigned char *nonce,
unsigned char *key);
byte *nonce,
byte *key);
/** Decrypt a symmetrically encrypted message.
@@ -79,11 +80,11 @@ size_t pcp_sodium_mac(unsigned char **cipher,
\return Returns 0 in case of success of -1 in case of an error. Check fatals_if_any().
*/
int pcp_sodium_verify_mac(unsigned char **cleartext,
unsigned char* message,
int pcp_sodium_verify_mac(byte **cleartext,
byte* message,
size_t messagesize,
unsigned char *nonce,
unsigned char *key);
byte *nonce,
byte *key);

View File

@@ -25,6 +25,7 @@
#include <string.h>
#include <stdlib.h>
#include "defines.h"
#include "platform.h"
/* simple malloc() wrapper */

View File

@@ -298,12 +298,12 @@ Buffer *pcp_export_c_pub(pcp_key_t *sk);
*/
Buffer *pcp_export_secret(pcp_key_t *sk, char *passphrase);
pcp_ks_bundle_t *pcp_import_pub(unsigned char *raw, size_t rawsize);
pcp_ks_bundle_t *pcp_import_pub(byte *raw, size_t rawsize);
pcp_ks_bundle_t *pcp_import_pub_rfc(Buffer *blob);
pcp_ks_bundle_t *pcp_import_pub_pbp(Buffer *blob);
/* import secret key */
pcp_key_t *pcp_import_secret(unsigned char *raw, size_t rawsize, char *passphrase);
pcp_key_t *pcp_import_secret(byte *raw, size_t rawsize, char *passphrase);
pcp_key_t *pcp_import_secret_native(Buffer *cipher, char *passphrase);
#endif // _HAVE_PCP_MGMT_H

View File

@@ -59,13 +59,13 @@
/* sample call: */
/* */
/* char unpadded[] = {0xef, 0xa5}; */
/* unsigned char *padded; */
/* byte *padded; */
/* pcp_pad_prepend(&padded, unpadded, 8, 2); */
/* */
/* the result, padded, would be 10 bytes long, 8 */
/* bytes for the leading zeros and 2 for the content */
/* of the original unpadded. */
void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
void pcp_pad_prepend(byte **padded, byte *unpadded,
size_t padlen, size_t unpadlen);
/* removes zero's of a binary stream, which is */
@@ -86,12 +86,12 @@ void pcp_pad_prepend(unsigned char **padded, unsigned char *unpadded,
/* sample call: */
/* */
/* char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; */
/* unsigned char *unpadded; */
/* byte *unpadded; */
/* pcp_pad_remove(unpadded, padded, 4, 2); */
/* */
/* the result, unpadded would be 2 bytes long containing */
/* only the 2 bytes we want to have with zeros removed. */
void pcp_pad_remove(unsigned char **unpadded, unsigned char *padded,
void pcp_pad_remove(byte **unpadded, byte *padded,
size_t padlen, size_t unpadlen);

View File

@@ -36,7 +36,7 @@
#include "mem.h"
#include "defines.h"
unsigned char * pcp_scrypt(char *passwd, size_t passwdlen, unsigned char *nonce, size_t noncelen);
byte * pcp_scrypt(char *passwd, size_t passwdlen, byte *nonce, size_t noncelen);
#endif /* _HAVE_PCP_SCRYPT_H */

View File

@@ -59,7 +59,7 @@ do {
/* a number of the hash function use uint32_t which isn't defined on win32 */
#ifdef _MSC_VER
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
typedef byte uint8_t;
#else
#include <inttypes.h> /* uint32_t */
#endif
@@ -416,7 +416,7 @@ do {
#define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \
do { \
unsigned _hj_i,_hj_j,_hj_k; \
unsigned char *_hj_key=(unsigned char*)(key); \
byte *_hj_key=(byte*)(key); \
hashv = 0xfeedbeef; \
_hj_i = _hj_j = 0x9e3779b9; \
_hj_k = (unsigned)(keylen); \
@@ -467,7 +467,7 @@ do {
#endif
#define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \
do { \
unsigned char *_sfh_key=(unsigned char*)(key); \
byte *_sfh_key=(byte*)(key); \
uint32_t _sfh_tmp, _sfh_len = keylen; \
\
int _sfh_rem = _sfh_len & 3; \

View File

@@ -37,7 +37,7 @@
#include <string.h>
#include <stdio.h>
#include "defines.h"
/** Convert a char array to lowercase.
@@ -74,7 +74,7 @@ char *_lc(char *in);
\return Returns the offset or -1 of the offset were not found.
*/
size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hlen);
size_t _findoffset(byte *bin, size_t binlen, char *sigstart, size_t hlen);
/** XOR an input buffer with another buffer.
@@ -87,7 +87,7 @@ size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hle
\param[in] xlen The size of the buffers (they must have the same size).
*/
void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen);
void _xorbuf(byte *iv, byte *buf, size_t xlen);
/** Dump binary data as hex to stderr.
@@ -97,7 +97,7 @@ void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen);
\param[in] s Size of d.
*/
void _dump(char *n, unsigned char *d, size_t s);
void _dump(char *n, byte *d, size_t s);
#endif /* _HAVE_PCP_UTIL_H */

View File

@@ -240,7 +240,7 @@ int pcpvault_copy(vault_t *tmp, vault_t *vault);
void pcpvault_unlink(vault_t *tmp);
/* calculate the vault checksum */
unsigned char *pcpvault_create_checksum(vault_t *vault);
byte *pcpvault_create_checksum(vault_t *vault);
/* write the new checksum to the header of the current vault */
void pcpvault_update_checksum(vault_t *vault);