Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airkiss: add aes-cbc-128 decryption #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ELF = airkiss
SRCS = main.c
SRCS += capture/common.c capture/osdep.c capture/linux.c capture/radiotap/radiotap-parser.c
SRCS += utils/wifi_scan.c airkiss.c
SRCS += utils/wifi_scan.c airkiss.c aes/aes.c aes/aes_dec.c
OBJS = $(patsubst %.c,%.o,$(SRCS))

LIBIW = -liw
Expand Down
31 changes: 31 additions & 0 deletions aes/aes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "aes.h"
#include <stdio.h>
#include <string.h>
extern void * aes_decrypt_init(const u8 *, size_t);
extern void * aes_decrypt(void *, const u8 *, u8 *);
extern void * aes_decrypt_deinit(void *);

int aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data, size_t data_len)
{
void *ctx;
u8 cbc[AES_BLOCK_SIZE], tmp[AES_BLOCK_SIZE];
u8 *pos = data;
int i, j, blocks;

ctx = aes_decrypt_init(key, 16);
if (ctx == NULL)
return -1;
memcpy(cbc, iv, AES_BLOCK_SIZE);

blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
memcpy(tmp, pos, AES_BLOCK_SIZE);
aes_decrypt(ctx, pos, pos);
for (j = 0; j < AES_BLOCK_SIZE; j++)
pos[j] ^= cbc[j];
memcpy(cbc, tmp, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_decrypt_deinit(ctx);
return 0;
}
10 changes: 10 additions & 0 deletions aes/aes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef AES_H_AK
#define AES_H_AK
#define AES_BLOCK_SIZE 16
#define AES_PRIV_SIZE (4 * 4 * 15 + 4)
#define AES_PRIV_NR_POS (4 * 15)

typedef unsigned char u8;
typedef unsigned int u32;

#endif
Loading