changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: libsec: make sectorNumber argument for aes_xts routines uvlong

changeset 6189: e018e9ad34fd
parent 6188: fff962c96ca6
tag:tip
author: cinap_lenrek@felloff.net
date: Tue, 17 Oct 2017 21:36:45 +0200
files: sys/include/ape/libsec.h sys/include/libsec.h sys/src/libsec/port/aes_xts.c
description: libsec: make sectorNumber argument for aes_xts routines uvlong
     1.1--- a/sys/include/ape/libsec.h
     1.2+++ b/sys/include/ape/libsec.h
     1.3@@ -509,8 +509,8 @@ uchar	*readcert(char *filename, int *pce
     1.4 PEMChain*readcertchain(char *filename);
     1.5 
     1.6 /* aes_xts.c */
     1.7-int aes_xts_encrypt(ulong tweak[], ulong ecb[],  vlong sectorNumber, uchar *input, uchar *output, ulong len) ;
     1.8-int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len);
     1.9+int aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) ;
    1.10+int aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len);
    1.11 
    1.12 typedef struct ECpoint{
    1.13 	int inf;
     2.1--- a/sys/include/libsec.h
     2.2+++ b/sys/include/libsec.h
     2.3@@ -502,8 +502,8 @@ uchar	*readcert(char *filename, int *pce
     2.4 PEMChain*readcertchain(char *filename);
     2.5 
     2.6 /* aes_xts.c */
     2.7-int aes_xts_encrypt(ulong tweak[], ulong ecb[],  vlong sectorNumber, uchar *input, uchar *output, ulong len) ;
     2.8-int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len);
     2.9+int aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) ;
    2.10+int aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len);
    2.11 
    2.12 typedef struct ECpoint{
    2.13 	int inf;
     3.1--- a/sys/src/libsec/port/aes_xts.c
     3.2+++ b/sys/src/libsec/port/aes_xts.c
     3.3@@ -3,16 +3,16 @@
     3.4 #include "os.h"
     3.5 #include <libsec.h>
     3.6 
     3.7-#define AesBlockSize 16
     3.8-
     3.9-static void xor128(uchar* o,uchar* i1,uchar* i2) {
    3.10+static void
    3.11+xor128(uchar *o, uchar *i1, uchar *i2) {
    3.12 	((ulong*)o)[0] = ((ulong*)i1)[0] ^ ((ulong*)i2)[0];
    3.13 	((ulong*)o)[1] = ((ulong*)i1)[1] ^ ((ulong*)i2)[1];
    3.14 	((ulong*)o)[2] = ((ulong*)i1)[2] ^ ((ulong*)i2)[2];
    3.15 	((ulong*)o)[3] = ((ulong*)i1)[3] ^ ((ulong*)i2)[3];
    3.16 }
    3.17 
    3.18-static void gf_mulx(uchar* x) {
    3.19+static void
    3.20+gf_mulx(uchar *x) {
    3.21     ulong t = ((((ulong*)(x))[3] & 0x80000000u) ? 0x00000087u : 0);;
    3.22     ((ulong*)(x))[3] = (((ulong*)(x))[3] << 1) | (((ulong*)(x))[2] & 0x80000000u ? 1 : 0);
    3.23     ((ulong*)(x))[2] = (((ulong*)(x))[2] << 1) | (((ulong*)(x))[1] & 0x80000000u ? 1 : 0);
    3.24@@ -21,21 +21,22 @@ static void gf_mulx(uchar* x) {
    3.25 
    3.26 }
    3.27 
    3.28-int aes_xts_encrypt(ulong tweak[], ulong ecb[],  vlong sectorNumber, uchar *input, uchar *output, ulong len) {
    3.29+int
    3.30+aes_xts_encrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) {
    3.31 	uchar T[16], x[16];
    3.32 	int i;
    3.33 	
    3.34 	if(len % 16 != 0)
    3.35 		return -1;
    3.36 
    3.37-	for(i=0; i<AesBlockSize; i++) {
    3.38+	for(i=0; i<AESbsize; i++) {
    3.39 		T[i] = (uchar)(sectorNumber & 0xFF);
    3.40 		sectorNumber = sectorNumber >> 8;
    3.41 	}
    3.42 	
    3.43 	aes_encrypt(tweak, 10, T, T);
    3.44 
    3.45-	for (i=0; i<len; i+=AesBlockSize) {
    3.46+	for (i=0; i<len; i+=AESbsize) {
    3.47 		xor128(&x[0], &input[i], &T[0]);
    3.48 		aes_encrypt(ecb, 10, x, x);
    3.49 		xor128(&output[i], &x[0], &T[0]);
    3.50@@ -44,21 +45,22 @@ int aes_xts_encrypt(ulong tweak[], ulong
    3.51 	return 0;
    3.52 }
    3.53 
    3.54-int aes_xts_decrypt(ulong tweak[], ulong ecb[], vlong sectorNumber, uchar *input, uchar *output, ulong len) {
    3.55+int
    3.56+aes_xts_decrypt(ulong tweak[], ulong ecb[], uvlong sectorNumber, uchar *input, uchar *output, ulong len) {
    3.57 	uchar T[16], x[16];
    3.58 	int i;
    3.59 	
    3.60 	if(len % 16 != 0)
    3.61 		return -1;
    3.62 
    3.63-	for(i=0; i<AesBlockSize; i++) {
    3.64+	for(i=0; i<AESbsize; i++) {
    3.65 		T[i] = (uchar)(sectorNumber & 0xFF);
    3.66 		sectorNumber = sectorNumber >> 8;
    3.67 	}
    3.68 	
    3.69 	aes_encrypt(tweak, 10, T, T);
    3.70 
    3.71-	for (i=0; i<len; i+=AesBlockSize) {
    3.72+	for (i=0; i<len; i+=AESbsize) {
    3.73 		xor128(&x[0], &input[i], &T[0]);
    3.74 		aes_decrypt(ecb, 10, x, x);
    3.75 		xor128(&output[i], &x[0], &T[0]);
    3.76@@ -66,4 +68,3 @@ int aes_xts_decrypt(ulong tweak[], ulong
    3.77 	}
    3.78 	return 0;
    3.79 }
    3.80-