diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-08-07 12:33:42 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-08-07 12:33:42 +0200 |
commit | fcb0130deaf8483fa130a3af7a2bb3451c2206a9 (patch) | |
tree | fe6f6abbd4d90e914ed505c81ccdda77ab7bd0a0 /libpiano/src/crypt.c | |
parent | c43af87ffb13775ea71795baa595e4633f9fd529 (diff) | |
parent | 0cd2322d48c8889e47a0d5ee635503c19cb6fb2b (diff) | |
download | pianobar-fcb0130deaf8483fa130a3af7a2bb3451c2206a9.tar.gz pianobar-fcb0130deaf8483fa130a3af7a2bb3451c2206a9.tar.bz2 pianobar-fcb0130deaf8483fa130a3af7a2bb3451c2206a9.zip |
Merge branch 'alloc_err'
Diffstat (limited to 'libpiano/src/crypt.c')
-rw-r--r-- | libpiano/src/crypt.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c index 67e2467..9b21516 100644 --- a/libpiano/src/crypt.c +++ b/libpiano/src/crypt.c @@ -38,20 +38,24 @@ THE SOFTWARE. /* decrypt hex-encoded, blowfish-crypted string: decode 2 hex-encoded blocks, * decrypt, byteswap * @param hex string - * @return decrypted string + * @return decrypted string or NULL */ #define INITIAL_SHIFT 28 #define SHIFT_DEC 4 unsigned char *PianoDecryptString (const unsigned char *strInput) { /* hex-decode => strlen/2 + null-byte */ - uint32_t *iDecrypt = calloc (strlen ((char *) strInput)/2/sizeof (*iDecrypt)+1, sizeof (*iDecrypt)); - unsigned char *strDecrypted = (unsigned char *) iDecrypt; - unsigned char shift = INITIAL_SHIFT; - unsigned char intsDecoded = 0; - unsigned char j; + uint32_t *iDecrypt; + unsigned char *strDecrypted; + unsigned char shift = INITIAL_SHIFT, intsDecoded = 0, j; /* blowfish blocks, 32-bit */ uint32_t f, l, r, lrExchange; + if ((iDecrypt = calloc (strlen ((char *) strInput)/2/sizeof (*iDecrypt)+1, + sizeof (*iDecrypt))) == NULL) { + return NULL; + } + strDecrypted = (unsigned char *) iDecrypt; + while (*strInput != '\0') { /* hex-decode string */ if (*strInput >= '0' && *strInput <= '9') { @@ -115,20 +119,29 @@ unsigned char *PianoEncryptString (const unsigned char *strInput) { const size_t strInputN = strlen ((char *) strInput); /* num of 64-bit blocks, rounded to next block */ size_t blockN = strInputN / 8 + 1; - uint32_t *blockInput = calloc (blockN*2, sizeof (*blockInput)); - uint32_t *blockPtr = blockInput; - /* encryption blocks */ - uint32_t f, lrExchange; - register uint32_t l, r; + uint32_t *blockInput, *blockPtr; /* output string */ - unsigned char *strHex = calloc (blockN*8*2 + 1, sizeof (*strHex)); - unsigned char *hexPtr = strHex; + unsigned char *strHex, *hexPtr; const char *hexmap = "0123456789abcdef"; - size_t i; + + if ((blockInput = calloc (blockN*2, sizeof (*blockInput))) == NULL) { + return NULL; + } + blockPtr = blockInput; + + if ((strHex = calloc (blockN*8*2 + 1, sizeof (*strHex))) == NULL) { + return NULL; + } + hexPtr = strHex; memcpy (blockInput, strInput, strInputN); while (blockN > 0) { + /* encryption blocks */ + uint32_t f, lrExchange; + register uint32_t l, r; + int i; + l = byteswap32 (*blockPtr); r = byteswap32 (*(blockPtr+1)); |