diff options
author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-08-08 19:37:31 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-08-08 19:37:31 +0200 |
commit | b55cf2b0641d67f9832b14285af741ef0ed9d8bf (patch) | |
tree | cf3596f231dd0a27892fc138060062e70aeb1e79 /libpiano/src/crypt.c | |
parent | e1cb484fe66410e45363f29b167fedf19f236ded (diff) | |
download | pianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.tar.gz pianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.tar.bz2 pianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.zip |
Several code optimizations
Diffstat (limited to 'libpiano/src/crypt.c')
-rw-r--r-- | libpiano/src/crypt.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c index 7a17927..dc5bf7b 100644 --- a/libpiano/src/crypt.c +++ b/libpiano/src/crypt.c @@ -37,19 +37,19 @@ THE SOFTWARE. */ void PianoHexToInts (const char *strHex, unsigned int **retInts, size_t *retIntsN) { - size_t i; + size_t i, strHexN = strlen (strHex); char hexInt[9]; - unsigned int *arrInts = calloc (strlen (strHex) / 8, sizeof (*arrInts)); + unsigned int *arrInts = calloc (strHexN / 8, sizeof (*arrInts)); /* FIXME: error handling: string too short, e.g. */ /* unsigned int = 4 bytes, 8 chars in hex */ - for (i = 0; i < strlen (strHex); i += 8) { + for (i = 0; i < strHexN; i += 8) { memcpy (hexInt, strHex+i, sizeof (hexInt)-1); sscanf (hexInt, "%x", &arrInts[i/8]); } *retInts = arrInts; /* FIXME: copy & waste */ - *retIntsN = strlen (strHex) / 8, sizeof (*arrInts); + *retIntsN = strHexN / 8, sizeof (*arrInts); } /* decipher int array; reverse engineered from pandora source @@ -138,12 +138,12 @@ char *PianoDecryptString (const char *strInput) { */ void PianoBytesToInts (const char *strInput, unsigned int **retArrInts, size_t *retArrIntsN) { - size_t i, j, neededStrLen = strlen (strInput); + size_t i, j, neededStrLen, strInputN = strlen (strInput); unsigned int *arrInts; char shift; /* blowfish encrypts two 4 byte blocks */ - neededStrLen = strlen (strInput); + neededStrLen = strInputN; if (neededStrLen % 8 != 0) { /* substract overhead and add full 8 byte block */ neededStrLen = neededStrLen - (neededStrLen % 8) + 8; @@ -155,9 +155,9 @@ void PianoBytesToInts (const char *strInput, unsigned int **retArrInts, shift = 24; i = 0; j = 0; - while (i < strlen (strInput)) { + while (i < strInputN) { shift = 24; - while (shift >= 0 && i < strlen (strInput)) { + while (shift >= 0 && i < strInputN) { arrInts[i/4] |= strInput[i] << shift; shift -= 8; i++; |