Exemple #1
0
int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                 const unsigned char *iv, int enc)
{
    int i;
    unsigned int key_len, mode;

    mode = EVP_CIPHER_CTX_mode(ctx) - 1;
    key_len = (ctx->key_len)/8 - 2;

    REG_MODE = 0x20;

    REG_AES = BC_INI(0, key_len, enc, mode, 0);

    for (i = 0; i < (4 + key_len * 2); i++)
        REG_KEY(i) = GETU32(key + i * 4);

    if (!mode) {
        for (i = 0; i < 4; i++)
            REG_IV(i) = GETU32(iv + i * 4);
    }

    // Key expension
    REG_AES = KEXP(0, key_len, enc, mode, 0);

    return 1;
}
Exemple #2
0
void
Camellia_DecryptBlock(const int keyBitLength, 
		      const unsigned char *ciphertext, 
		      const uint32_t *subkey,
		      unsigned char *plaintext)
{
    uint32_t tmp[4];
 
    tmp[0] = GETU32(ciphertext);
    tmp[1] = GETU32(ciphertext + 4);
    tmp[2] = GETU32(ciphertext + 8);
    tmp[3] = GETU32(ciphertext + 12);

    switch (keyBitLength) {
    case 128:
	camellia_decrypt128(subkey, tmp);
	break;
    case 192:
	/* fall through */
    case 256:
	camellia_decrypt256(subkey, tmp);
	break;
    default:
	break;
    }

    PUTU32(plaintext,    tmp[0]);
    PUTU32(plaintext+4,  tmp[1]);
    PUTU32(plaintext+8,  tmp[2]);
    PUTU32(plaintext+12, tmp[3]);
}
Exemple #3
0
/* increment counter (128-bit int) by 1 */
static void AES_ctr128_inc(unsigned char *counter) {
	unsigned long c;

	/* Grab bottom dword of counter and increment */
	c = GETU32(counter + 12);
	c++;	c &= 0xFFFFFFFF;
	PUTU32(counter + 12, c);

	/* if no overflow, we're done */
	if (c)
		return;

	/* Grab 1st dword of counter and increment */
	c = GETU32(counter +  8);
	c++;	c &= 0xFFFFFFFF;
	PUTU32(counter +  8, c);

	/* if no overflow, we're done */
	if (c)
		return;

	/* Grab 2nd dword of counter and increment */
	c = GETU32(counter +  4);
	c++;	c &= 0xFFFFFFFF;
	PUTU32(counter +  4, c);

	/* if no overflow, we're done */
	if (c)
		return;

	/* Grab top dword of counter and increment */
	c = GETU32(counter +  0);
	c++;	c &= 0xFFFFFFFF;
	PUTU32(counter +  0, c);
}
Exemple #4
0
/* increment counter (128-bit int) by 2^64 */
void AES_ctr128_inc(unsigned char *counter) {
	unsigned long c;

	/* Grab 3rd dword of counter and increment */
#ifdef L_ENDIAN
	c = GETU32(counter + 8);
	c++;
	PUTU32(counter + 8, c);
#else
	c = GETU32(counter + 4);
	c++;
	PUTU32(counter + 4, c);
#endif

	/* if no overflow, we're done */
	if (c)
		return;

	/* Grab top dword of counter and increment */
#ifdef L_ENDIAN
	c = GETU32(counter + 12);
	c++;
	PUTU32(counter + 12, c);
#else
	c = GETU32(counter +  0);
	c++;
	PUTU32(counter +  0, c);
#endif

}
Exemple #5
0
int do_append(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,inode_src;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(inode_src,ptr);
	EAT(ptr,filename,lv,')');
	return fs_log_append(ts,inode,inode_src);
}
Exemple #6
0
uint8_t do_append(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode,inode_src;
        EAT(ptr,lv,'(');
        GETU32(inode,ptr);
        EAT(ptr,lv,',');
        GETU32(inode_src,ptr);
        EAT(ptr,lv,')');
        return shadow_fs_append(ts,inode,inode_src);
}
Exemple #7
0
uint8_t do_emptytrash(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t reservedinodes,freeinodes;
        EAT(ptr,lv,'(');
        EAT(ptr,lv,')');
        EAT(ptr,lv,':');
        GETU32(freeinodes,ptr);
        EAT(ptr,lv,',');
        GETU32(reservedinodes,ptr);
        return shadow_fs_emptytrash(ts,freeinodes,reservedinodes);
}
Exemple #8
0
uint8_t do_aquire(uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,cuid;
	(void)ts;
	EAT(ptr,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,lv,',');
	GETU32(cuid,ptr);
	EAT(ptr,lv,')');
	return fs_aquire(inode,cuid);
}
Exemple #9
0
uint8_t do_release(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode,cuid;
        (void)ts;
        EAT(ptr,lv,'(');
        GETU32(inode,ptr);
        EAT(ptr,lv,',');
        GETU32(cuid,ptr);
        EAT(ptr,lv,')');
        return shadow_fs_release(inode,cuid);
}
Exemple #10
0
int do_emptytrash(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t reservedinodes,freeinodes;
	EAT(ptr,filename,lv,'(');
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(freeinodes,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(reservedinodes,ptr);
	return fs_log_emptytrash(ts,freeinodes,reservedinodes);
}
Exemple #11
0
void rijndaelKeySetupEnc_Master(u32 *rk, const u8 cipherKey[], int rank)
{
	rk[0] = GETU32(cipherKey     );
	rk[1] = GETU32(cipherKey +  4);
	rk[2] = GETU32(cipherKey +  8);
	rk[3] = GETU32(cipherKey + 12);

	int * rk_sign = (int*)rk;
	MPI_Send(rk_sign, 4, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
Exemple #12
0
/*
int do_reinit(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,indx;
	uint64_t chunkid;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(indx,ptr);
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU64(chunkid,ptr);
	return fs_log_reinit(ts,inode,indx,chunkid);
}
*/
int do_release(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,cuid;
	(void)ts;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(cuid,ptr);
	EAT(ptr,filename,lv,')');
	return fs_log_release(inode,cuid);
}
Exemple #13
0
int do_repair(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,indx;
	uint32_t version;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(indx,ptr);
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(version,ptr);
	return fs_log_repair(ts,inode,indx,version);
}
Exemple #14
0
int do_unlink(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,parent;
	uint8_t name[256];
	EAT(ptr,filename,lv,'(');
	GETU32(parent,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name,ptr,filename,lv,')');
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(inode,ptr);
	return fs_log_unlink(ts,parent,strlen((char*)name),name,inode);
}
Exemple #15
0
int do_trunc(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,indx;
	uint64_t chunkid;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(indx,ptr);
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU64(chunkid,ptr);
	return fs_log_trunc(ts,inode,indx,chunkid);
}
Exemple #16
0
uint8_t do_trunc(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode,indx;
        uint64_t chunkid;
        EAT(ptr,lv,'(');
        GETU32(inode,ptr);
        EAT(ptr,lv,',');
        GETU32(indx,ptr);
        EAT(ptr,lv,')');
        EAT(ptr,lv,':');
        GETU64(chunkid,ptr);
        return shadow_fs_trunc(ts,inode,indx,chunkid);
}
Exemple #17
0
uint8_t do_unlink(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode,parent;
        uint8_t name[256];
        EAT(ptr,lv,'(');
        GETU32(parent,ptr);
        EAT(ptr,lv,',');
        GETNAME(name,ptr,lv,')');
        EAT(ptr,lv,')');
        EAT(ptr,lv,':');
        GETU32(inode,ptr);
        return shadow_fs_unlink(ts,parent,strlen((char*)name),name,inode);
}
Exemple #18
0
uint8_t do_repair(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode,indx;
        uint32_t version;
        EAT(ptr,lv,'(');
        GETU32(inode,ptr);
        EAT(ptr,lv,',');
        GETU32(indx,ptr);
        EAT(ptr,lv,')');
        EAT(ptr,lv,':');
        GETU32(version,ptr);
        return shadow_fs_repair(ts,inode,indx,version);
}
Exemple #19
0
int do_setgoal(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
#if VERSHEX>=0x010700
	uint32_t inode,uid,ci,nci,npi,qei;
#else
	uint32_t inode,uid,ci,nci,npi;
#endif
	uint8_t goal,smode;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(uid,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(goal,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(smode,ptr);
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(ci,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(nci,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(npi,ptr);
#if VERSHEX>=0x010700
	if (*ptr==',') {
		EAT(ptr,filename,lv,',');
		GETU32(qei,ptr);
	} else {
		qei = UINT32_C(0xFFFFFFFF);
	}
	return fs_log_setgoal(ts,inode,uid,goal,smode,ci,nci,npi,qei);
#else
	return fs_log_setgoal(ts,inode,uid,goal,smode,ci,nci,npi);
#endif
}
Exemple #20
0
int do_snapshot(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,parent,canoverwrite;
	uint8_t name[256];
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETU32(parent,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name,ptr,filename,lv,',');
	EAT(ptr,filename,lv,',');
	GETU32(canoverwrite,ptr);
	EAT(ptr,filename,lv,')');
	return fs_log_snapshot(ts,inode,parent,strlen((char*)name),name,canoverwrite);
}
Exemple #21
0
void rijndaelDecrypt_Master(const u32 rk[/*44*/], const u8 pt[16], int rank)
{
	u32 s[4];
	/*
	 * map byte array block to cipher state
	 * and add initial round key:
	 */
	s[0] = GETU32(pt     ) ^ rk[0];
	s[1] = GETU32(pt +  4) ^ rk[1];
	s[2] = GETU32(pt +  8) ^ rk[2];
	s[3] = GETU32(pt + 12) ^ rk[3];

	int * s_sign = (int*)s;
	MPI_Send(s_sign, 4, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
Exemple #22
0
void sms4_encrypt(const unsigned char *in, unsigned char *out, const sms4_key_t *key)
{
	const uint32_t *rk = key->rk;
	uint32_t X0, X1, X2, X3, X4;

	X0 = GETU32(in     );
	X1 = GETU32(in +  4);
	X2 = GETU32(in +  8);
	X3 = GETU32(in + 12);

	ROUND(X0, X1, X2, X3, X4, rk[0]);
	ROUND(X1, X2, X3, X4, X0, rk[1]);
	ROUND(X2, X3, X4, X0, X1, rk[2]);
	ROUND(X3, X4, X0, X1, X2, rk[3]);
	ROUND(X4, X0, X1, X2, X3, rk[4]);
	ROUND(X0, X1, X2, X3, X4, rk[5]);
	ROUND(X1, X2, X3, X4, X0, rk[6]);
	ROUND(X2, X3, X4, X0, X1, rk[7]);
	ROUND(X3, X4, X0, X1, X2, rk[8]);
	ROUND(X4, X0, X1, X2, X3, rk[9]);
	ROUND(X0, X1, X2, X3, X4, rk[10]);
	ROUND(X1, X2, X3, X4, X0, rk[11]);
	ROUND(X2, X3, X4, X0, X1, rk[12]);
	ROUND(X3, X4, X0, X1, X2, rk[13]);
	ROUND(X4, X0, X1, X2, X3, rk[14]);
	ROUND(X0, X1, X2, X3, X4, rk[15]);
	ROUND(X1, X2, X3, X4, X0, rk[16]);
	ROUND(X2, X3, X4, X0, X1, rk[17]);
	ROUND(X3, X4, X0, X1, X2, rk[18]);
	ROUND(X4, X0, X1, X2, X3, rk[19]);
	ROUND(X0, X1, X2, X3, X4, rk[20]);
	ROUND(X1, X2, X3, X4, X0, rk[21]);
	ROUND(X2, X3, X4, X0, X1, rk[22]);
	ROUND(X3, X4, X0, X1, X2, rk[23]);
	ROUND(X4, X0, X1, X2, X3, rk[24]);
	ROUND(X0, X1, X2, X3, X4, rk[25]);
	ROUND(X1, X2, X3, X4, X0, rk[26]);
	ROUND(X2, X3, X4, X0, X1, rk[27]);
	ROUND(X3, X4, X0, X1, X2, rk[28]);
	ROUND(X4, X0, X1, X2, X3, rk[29]);
	ROUND(X0, X1, X2, X3, X4, rk[30]);
	ROUND(X1, X2, X3, X4, X0, rk[31]);

	PUTU32(X0, out);
	PUTU32(X4, out + 4);
	PUTU32(X3, out + 8);
	PUTU32(X2, out + 12);
}
Exemple #23
0
int aes_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
               const unsigned char *in, size_t len)
{
    int block;
    int i, j;
    unsigned int mode, key_len;

    mode = EVP_CIPHER_CTX_mode(ctx) - 1;
    key_len = (ctx->key_len)/8 - 2;

    block = len / 16;

    for (i = 0; i < block; i++) {
        for (j = 0; j < 4; j++) {
            REG_TEXT(j) = GETU32(in + i*16 + j*4);
        }

        REG_AES = ED(0, key_len, ctx->encrypt, mode, 0, 0);

        int a[5];
        a[4] = REG_RESULT(0);
        for (j = 0; j < 4; j++) {
            a[j] = REG_RESULT(j);
        }

        for (j = 0; j < 4; j++) {
            PUTU32(a[j], out + i*16 + j*4);
        }
    }

    return 1;
}
Exemple #24
0
uint8_t do_purge(uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode;
	EAT(ptr,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,lv,')');
	return fs_purge(ts,inode);
}
Exemple #25
0
int do_undel(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,')');
	return fs_log_undel(ts,inode);
}
Exemple #26
0
int do_setxattr(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,valueleng,mode;
	uint8_t name[256];
	static uint8_t *value = NULL;
	static uint32_t valuesize = 0;
	EAT(ptr,filename,lv,'(');
	GETU32(inode,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name,ptr,filename,lv,',');
	EAT(ptr,filename,lv,',');
	GETDATA(value,valueleng,valuesize,ptr,filename,lv,',');
	EAT(ptr,filename,lv,',');
	GETU32(mode,ptr);
	EAT(ptr,filename,lv,')');
	return fs_log_setxattr(ts,inode,strlen((char*)name),name,valueleng,value,mode);
}
Exemple #27
0
uint8_t do_undel(uint64_t lv,uint32_t ts,char *ptr) {
        uint32_t inode;
        EAT(ptr,lv,'(');
        GETU32(inode,ptr);
        EAT(ptr,lv,')');
        return shadow_fs_undel(ts,inode);
}
Exemple #28
0
int do_move(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,parent_src,parent_dst;
	uint8_t name_src[256],name_dst[256];
	EAT(ptr,filename,lv,'(');
	GETU32(parent_src,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name_src,ptr,filename,lv,',');
	EAT(ptr,filename,lv,',');
	GETU32(parent_dst,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name_dst,ptr,filename,lv,')');
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(inode,ptr);
	return fs_log_move(ts,parent_src,strlen((char*)name_src),name_src,parent_dst,strlen((char*)name_dst),name_dst,inode);
}
Exemple #29
0
uint8_t do_freeinodes(uint64_t lv,uint32_t ts,char* ptr) {
        uint32_t freeinodes;
        EAT(ptr,lv,'(');
        EAT(ptr,lv,')');
        EAT(ptr,lv,':');
        GETU32(freeinodes,ptr);
        return shadow_fs_freeinodes(ts,freeinodes);
}
Exemple #30
0
int do_freeinodes(const char *filename,uint64_t lv,uint32_t ts,char* ptr) {
	uint32_t freeinodes;
	EAT(ptr,filename,lv,'(');
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(freeinodes,ptr);
	return fs_log_freeinodes(ts,freeinodes);
}