summaryrefslogtreecommitdiff
path: root/wsutil/eax.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2014-10-14 11:12:16 -0400
committerBill Meier <wmeier@newsguy.com>2014-10-14 16:45:09 +0000
commit10b83e6931debe1f1f2ea4edce86ddf168995e51 (patch)
treefb8b987b896ded10ce6e1f9a4fa344ccdd987515 /wsutil/eax.c
parent2359e67f9c42cc285935c70fe8e9cc6b9f369797 (diff)
downloadwireshark-10b83e6931debe1f1f2ea4edce86ddf168995e51.tar.gz
Add editor-modelines; adjust whitespace.
Change-Id: I8cad872cee972a6d22a72852dac57fd188daca84 Reviewed-on: https://code.wireshark.org/review/4683 Reviewed-by: Bill Meier <wmeier@newsguy.com>
Diffstat (limited to 'wsutil/eax.c')
-rw-r--r--wsutil/eax.c141
1 files changed, 77 insertions, 64 deletions
diff --git a/wsutil/eax.c b/wsutil/eax.c
index 4243766fc3..a428c6be6d 100644
--- a/wsutil/eax.c
+++ b/wsutil/eax.c
@@ -48,20 +48,20 @@ void AesEncrypt(unsigned char msg[EAX_SIZEOF_KEY], unsigned char key[EAX_SIZEOF_
/*!
Decrypts cleartext data using EAX' mode (see ANSI Standard C12.22-2008).
- @param[in] pN pointer to cleartext (canonified form)
- @param[in] pK pointer to secret key
- @param[in,out] pC pointer to ciphertext
- @param[in] SizeN byte length of cleartext (pN) buffer
- @param[in] SizeK byte length of secret key (pK)
- @param[in] SizeC byte length of ciphertext (pC) buffer
- @param[in] pMac four-byte Message Authentication Code
- @param[in] Mode EAX_MODE_CLEARTEXT_AUTH or EAX_MODE_CIPHERTEXT_AUTH
- @return TRUE if message has been authenticated; FALSE if not
- authenticated, invalid Mode or error
+ @param[in] pN pointer to cleartext (canonified form)
+ @param[in] pK pointer to secret key
+ @param[in,out] pC pointer to ciphertext
+ @param[in] SizeN byte length of cleartext (pN) buffer
+ @param[in] SizeK byte length of secret key (pK)
+ @param[in] SizeC byte length of ciphertext (pC) buffer
+ @param[in] pMac four-byte Message Authentication Code
+ @param[in] Mode EAX_MODE_CLEARTEXT_AUTH or EAX_MODE_CIPHERTEXT_AUTH
+ @return TRUE if message has been authenticated; FALSE if not
+ authenticated, invalid Mode or error
*/
gboolean Eax_Decrypt(guint8 *pN, guint8 *pK, guint8 *pC,
- guint32 SizeN, guint32 SizeK, guint32 SizeC, MAC_T *pMac,
- guint8 Mode)
+ guint32 SizeN, guint32 SizeK, guint32 SizeC, MAC_T *pMac,
+ guint8 Mode)
{
guint8 wsn[EAX_SIZEOF_KEY];
guint8 wsc[EAX_SIZEOF_KEY];
@@ -69,11 +69,11 @@ gboolean Eax_Decrypt(guint8 *pN, guint8 *pK, guint8 *pC,
/* key size must match this implementation */
if (SizeK != EAX_SIZEOF_KEY)
- return FALSE;
+ return FALSE;
/* the key is new */
for (i = 0; i < EAX_SIZEOF_KEY; i++)
- instance.L[i] = 0;
+ instance.L[i] = 0;
AesEncrypt(instance.L, pK);
Dbl(instance.D, instance.L);
Dbl(instance.Q, instance.D);
@@ -81,13 +81,13 @@ gboolean Eax_Decrypt(guint8 *pN, guint8 *pK, guint8 *pC,
/* first copy the nonce into our working space */
BLK_CPY(wsn, instance.D);
if (Mode == EAX_MODE_CLEARTEXT_AUTH) {
- dCMAC(pK, wsn, pN, SizeN, pC, SizeC);
+ dCMAC(pK, wsn, pN, SizeN, pC, SizeC);
} else {
- CMAC(pK, wsn, pN, SizeN);
+ CMAC(pK, wsn, pN, SizeN);
}
/*
* In authentication mode the inputs are: pN, pK (and associated sizes),
- * the result is the 4 byte MAC.
+ * the result is the 4 byte MAC.
*/
if (Mode == EAX_MODE_CLEARTEXT_AUTH)
{
@@ -101,19 +101,19 @@ gboolean Eax_Decrypt(guint8 *pN, guint8 *pK, guint8 *pC,
*/
else if (Mode == EAX_MODE_CIPHERTEXT_AUTH)
{
- if (SizeC == 0)
+ if (SizeC == 0)
return (memcmp(pMac, &wsn[EAX_SIZEOF_KEY-sizeof(*pMac)], sizeof(*pMac)) ? FALSE : TRUE);
- {
- /* first copy the nonce into our working space */
- BLK_CPY(wsc, instance.Q);
- CMAC(pK, wsc, pC, SizeC);
- BLK_XOR(wsc, wsn);
- }
- if (memcmp(pMac, &wsc[EAX_SIZEOF_KEY-sizeof(*pMac)], sizeof(*pMac)) == 0)
- {
- CTR(wsn, pK, pC, SizeC);
- return TRUE;
- }
+ {
+ /* first copy the nonce into our working space */
+ BLK_CPY(wsc, instance.Q);
+ CMAC(pK, wsc, pC, SizeC);
+ BLK_XOR(wsc, wsn);
+ }
+ if (memcmp(pMac, &wsc[EAX_SIZEOF_KEY-sizeof(*pMac)], sizeof(*pMac)) == 0)
+ {
+ CTR(wsn, pK, pC, SizeC);
+ return TRUE;
+ }
}
return FALSE;
}
@@ -127,11 +127,11 @@ static void Dbl(guint8 *out, const guint8 *in)
/* this might be a lot more efficient in assembly language */
for (i=0; i < EAX_SIZEOF_KEY; i++)
{
- out[i] = ( in[i] << 1 ) | carry;
- carry = (in[i] & 0x80) ? 1 : 0;
+ out[i] = ( in[i] << 1 ) | carry;
+ carry = (in[i] & 0x80) ? 1 : 0;
}
if (carry)
- out[0] ^= 0x87;
+ out[0] ^= 0x87;
}
static void CMAC(guint8 *pK, guint8 *ws, const guint8 *pN, guint16 SizeN)
@@ -149,11 +149,11 @@ static void dCMAC(guint8 *pK, guint8 *ws, const guint8 *pN, guint16 SizeN, const
/* worksize must be an integral multiple of 16 */
if (SizeT & 0xf) {
- worksize += 0x10 - (worksize & 0xf);
+ worksize += 0x10 - (worksize & 0xf);
}
work = (guint8 *)g_malloc(worksize);
if (work == NULL) {
- return;
+ return;
}
memcpy(work, pN, SizeN);
if (pC != NULL) {
@@ -164,34 +164,34 @@ static void dCMAC(guint8 *pK, guint8 *ws, const guint8 *pN, guint16 SizeN, const
* whether data was padded or not
*/
if (worksize != SizeT) {
- work[SizeT] = 0x80;
- for (ptr = &work[SizeT+1]; ptr < &work[worksize]; ptr++)
- *ptr = 0;
- ptr= &work[worksize-0x10];
- BLK_XOR(ptr, instance.Q);
+ work[SizeT] = 0x80;
+ for (ptr = &work[SizeT+1]; ptr < &work[worksize]; ptr++)
+ *ptr = 0;
+ ptr= &work[worksize-0x10];
+ BLK_XOR(ptr, instance.Q);
} else {
- ptr = &work[worksize-0x10];
- BLK_XOR(ptr, instance.D);
+ ptr = &work[worksize-0x10];
+ BLK_XOR(ptr, instance.D);
}
/* open the cipher */
if (gcry_cipher_open(&cipher_hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC,0)){/* GCRY_CIPHER_CBC_MAC)) { */
- g_free(work);
- return;
+ g_free(work);
+ return;
}
if (gcry_cipher_setkey(cipher_hd, pK, EAX_SIZEOF_KEY)) {
- g_free(work);
- gcry_cipher_close(cipher_hd);
- return;
+ g_free(work);
+ gcry_cipher_close(cipher_hd);
+ return;
}
if (gcry_cipher_setiv(cipher_hd, ws, EAX_SIZEOF_KEY)) {
- g_free(work);
- gcry_cipher_close(cipher_hd);
- return;
+ g_free(work);
+ gcry_cipher_close(cipher_hd);
+ return;
}
if (gcry_cipher_encrypt(cipher_hd, work, worksize, work, worksize)) {
- g_free(work);
- gcry_cipher_close(cipher_hd);
- return;
+ g_free(work);
+ gcry_cipher_close(cipher_hd);
+ return;
}
memcpy(ws, ptr, EAX_SIZEOF_KEY);
@@ -210,19 +210,19 @@ static void CTR(const guint8 *ws, guint8 *pK, guint8 *pN, guint16 SizeN)
ctr[14] &= 0x7f;
/* open the cipher */
if (gcry_cipher_open(&cipher_hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0)) {
- return;
+ return;
}
if (gcry_cipher_setkey(cipher_hd, pK, EAX_SIZEOF_KEY)) {
- gcry_cipher_close(cipher_hd);
- return;
+ gcry_cipher_close(cipher_hd);
+ return;
}
if (gcry_cipher_setctr(cipher_hd, ctr, EAX_SIZEOF_KEY)) {
- gcry_cipher_close(cipher_hd);
- return;
+ gcry_cipher_close(cipher_hd);
+ return;
}
if (gcry_cipher_encrypt(cipher_hd, pN, SizeN, pN, SizeN)) {
- gcry_cipher_close(cipher_hd);
- return;
+ gcry_cipher_close(cipher_hd);
+ return;
}
gcry_cipher_close(cipher_hd);
return;
@@ -234,17 +234,30 @@ void AesEncrypt(unsigned char msg[EAX_SIZEOF_KEY], unsigned char key[EAX_SIZEOF_
/* open the cipher */
if (gcry_cipher_open(&cipher_hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0)) {
- return;
+ return;
}
if (gcry_cipher_setkey(cipher_hd, key, EAX_SIZEOF_KEY)) {
- gcry_cipher_close(cipher_hd);
- return;
+ gcry_cipher_close(cipher_hd);
+ return;
}
if (gcry_cipher_encrypt(cipher_hd, msg, EAX_SIZEOF_KEY, msg, EAX_SIZEOF_KEY)) {
- gcry_cipher_close(cipher_hd);
- return;
+ gcry_cipher_close(cipher_hd);
+ return;
}
gcry_cipher_close(cipher_hd);
return;
}
#endif /* HAVE_LIBGCRYPT */
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */