libsec: make sectorNumber argument for aes_xts routines uvlong
This commit is contained in:
parent
45b7d60bf3
commit
29411f58cf
3 changed files with 16 additions and 15 deletions
|
@ -509,8 +509,8 @@ uchar *readcert(char *filename, int *pcertlen);
|
|||
PEMChain*readcertchain(char *filename);
|
||||
|
||||
/* aes_xts.c */
|
||||
int aes_xts_encrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len) ;
|
||||
int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len);
|
||||
int aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) ;
|
||||
int aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len);
|
||||
|
||||
typedef struct ECpoint{
|
||||
int inf;
|
||||
|
|
|
@ -502,8 +502,8 @@ uchar *readcert(char *filename, int *pcertlen);
|
|||
PEMChain*readcertchain(char *filename);
|
||||
|
||||
/* aes_xts.c */
|
||||
int aes_xts_encrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len) ;
|
||||
int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len);
|
||||
int aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) ;
|
||||
int aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len);
|
||||
|
||||
typedef struct ECpoint{
|
||||
int inf;
|
||||
|
|
|
@ -3,16 +3,16 @@
|
|||
#include "os.h"
|
||||
#include <libsec.h>
|
||||
|
||||
#define AesBlockSize 16
|
||||
|
||||
static void xor128(uchar* o,uchar* i1,uchar* i2) {
|
||||
static void
|
||||
xor128(uchar *o, uchar *i1, uchar *i2) {
|
||||
((ulong*)o)[0] = ((ulong*)i1)[0] ^ ((ulong*)i2)[0];
|
||||
((ulong*)o)[1] = ((ulong*)i1)[1] ^ ((ulong*)i2)[1];
|
||||
((ulong*)o)[2] = ((ulong*)i1)[2] ^ ((ulong*)i2)[2];
|
||||
((ulong*)o)[3] = ((ulong*)i1)[3] ^ ((ulong*)i2)[3];
|
||||
}
|
||||
|
||||
static void gf_mulx(uchar* x) {
|
||||
static void
|
||||
gf_mulx(uchar *x) {
|
||||
ulong t = ((((ulong*)(x))[3] & 0x80000000u) ? 0x00000087u : 0);;
|
||||
((ulong*)(x))[3] = (((ulong*)(x))[3] << 1) | (((ulong*)(x))[2] & 0x80000000u ? 1 : 0);
|
||||
((ulong*)(x))[2] = (((ulong*)(x))[2] << 1) | (((ulong*)(x))[1] & 0x80000000u ? 1 : 0);
|
||||
|
@ -21,21 +21,22 @@ static void gf_mulx(uchar* x) {
|
|||
|
||||
}
|
||||
|
||||
int aes_xts_encrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len) {
|
||||
int
|
||||
aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) {
|
||||
uchar T[16], x[16];
|
||||
int i;
|
||||
|
||||
if(len % 16 != 0)
|
||||
return -1;
|
||||
|
||||
for(i=0; i<AesBlockSize; i++) {
|
||||
for(i=0; i<AESbsize; i++) {
|
||||
T[i] = (uchar)(sectorNumber & 0xFF);
|
||||
sectorNumber = sectorNumber >> 8;
|
||||
}
|
||||
|
||||
aes_encrypt(tweak, 10, T, T);
|
||||
|
||||
for (i=0; i<len; i+=AesBlockSize) {
|
||||
for (i=0; i<len; i+=AESbsize) {
|
||||
xor128(&x[0], &input[i], &T[0]);
|
||||
aes_encrypt(ecb, 10, x, x);
|
||||
xor128(&output[i], &x[0], &T[0]);
|
||||
|
@ -44,21 +45,22 @@ int aes_xts_encrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *inpu
|
|||
return 0;
|
||||
}
|
||||
|
||||
int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len) {
|
||||
int
|
||||
aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) {
|
||||
uchar T[16], x[16];
|
||||
int i;
|
||||
|
||||
if(len % 16 != 0)
|
||||
return -1;
|
||||
|
||||
for(i=0; i<AesBlockSize; i++) {
|
||||
for(i=0; i<AESbsize; i++) {
|
||||
T[i] = (uchar)(sectorNumber & 0xFF);
|
||||
sectorNumber = sectorNumber >> 8;
|
||||
}
|
||||
|
||||
aes_encrypt(tweak, 10, T, T);
|
||||
|
||||
for (i=0; i<len; i+=AesBlockSize) {
|
||||
for (i=0; i<len; i+=AESbsize) {
|
||||
xor128(&x[0], &input[i], &T[0]);
|
||||
aes_decrypt(ecb, 10, x, x);
|
||||
xor128(&output[i], &x[0], &T[0]);
|
||||
|
@ -66,4 +68,3 @@ int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue