ref: 29411f58cfa62a7d05713070338d82b722364665
parent: 45b7d60bf385aa9ac0bab7bb8c694f8221893024
author: cinap_lenrek <[email protected]>
date: Tue Oct 17 17:36:45 EDT 2017
libsec: make sectorNumber argument for aes_xts routines uvlong
--- a/sys/include/ape/libsec.h
+++ b/sys/include/ape/libsec.h
@@ -509,8 +509,8 @@
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;
--- a/sys/include/libsec.h
+++ b/sys/include/libsec.h
@@ -502,8 +502,8 @@
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;
--- a/sys/src/libsec/port/aes_xts.c
+++ b/sys/src/libsec/port/aes_xts.c
@@ -3,9 +3,8 @@
#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];
@@ -12,7 +11,8 @@
((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,7 +21,8 @@
}
-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;
@@ -28,7 +29,7 @@
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;
}
@@ -35,7 +36,7 @@
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,7 +45,8 @@
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;
@@ -51,7 +53,7 @@
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;
}
@@ -58,7 +60,7 @@
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 @@
}
return 0;
}
-