Exemplo n.º 1
0
static MinixInode *search_dir(MinixInode *di,String name){
    if(isNullp(di)) return NULL;
    static char block[BLOCK_SIZE];
    MinixDirentry *drp = (MinixDirentry *)block;
    MinixInode *inode = malloc(sizeof(MinixInode));
    if(inode == NULL) goto error_ret;

    zone_t dnoze = FULL_BLOCK(di->i_size);
    for(int i = 0;i < dnoze;i++){
        if(ERROR == zone_rw(di,READ,i,block)){
            zerror("search_dir : zone_rw fail");
            goto error_ret;
        }
        for(int j = 0;j < DIR_IN_BLOCK;j++){
            if(_isEqName(name,drp[j].name)){
                if(ERROR == get_inode(drp[j].inode,inode))
                    goto error_ret;
                return inode;
            }
        }
    }
error_ret:
    if(inode) free(inode);
    return NULL;
}
Exemplo n.º 2
0
/**
 * @brief CTR en/decryption of buffer 'buf'
 *
 * @param[in,out]       nonce     The nonce (as "IV"), 1st and last byte
 *                                will be changed!
 * @param[in,out]       buf       Plain resp. ciphertext, MIC is first block
 * @param[in]           len       Number of encrypted bytes
 */
static void ctr_crypt(uint8_t *nonce, uint8_t *buf, uint8_t len)
{
	nonce[0] = 1;
	nonce[AES_BLOCKSIZE - 1] = 0;   /* counter value for MIC */

	/* Set mode */
	AT91C_BASE_AES->AES_MR = AT91C_AES_OPMOD_CTR | AT91C_AES_CIPHER |
			AT91C_AES_SMOD_PDC;

	/* Init CTR*/
	memcpy((void *)(AT91C_BASE_AES->AES_IVxR), nonce, AES_BLOCKSIZE);

	/* Set PDC */
	AT91C_BASE_AES->AES_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;
	AT91C_BASE_AES->AES_TPR = AT91C_BASE_AES->AES_RPR = (uint32_t)(buf);
	AT91C_BASE_AES->AES_TCR = AT91C_BASE_AES->AES_RCR = FULL_BLOCK(len) / 4;

	/* Start encryption */
	AT91C_BASE_AES->AES_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN;

	/* Wait for end */
	while (!(AT91C_BASE_AES->AES_ISR & AT91C_AES_ENDRX)) {
	}
}
Exemplo n.º 3
0
/**
 * @brief Compute MIC of buffer
 *
 * @param[in]       nonce     The nonce (as "IV")
 * @param[in,out]   buf       Buffer with plaintext, nonce will be
 *                            stored in first block
 * @param[in]       len       Number of plaintext bytes (with nonce)
 * @param[in]       micoff    Offset of 'buf' where MIC is stored
 */
static void compute_mic(uint8_t *nonce,
		uint8_t *buf,
		uint8_t len,
		uint8_t micoff)
{
	memcpy(buf, nonce, AES_BLOCKSIZE);

	/* Set mode */
	AT91C_BASE_AES->AES_MR = AT91C_AES_LOD | AT91C_AES_CIPHER |
			AT91C_AES_OPMOD_CBC | AT91C_AES_SMOD_PDC;

	memset((void *)(AT91C_BASE_AES->AES_IVxR), 0, AES_BLOCKSIZE);

	/* Set PDC */
	AT91C_BASE_AES->AES_PTCR = AT91C_PDC_RXTDIS | AT91C_PDC_TXTDIS;
	AT91C_BASE_AES->AES_TPR = (uint32_t)buf;
	AT91C_BASE_AES->AES_TCR = FULL_BLOCK(len) / 4;

	/* Start encryption */
	AT91C_BASE_AES->AES_PTCR = AT91C_PDC_TXTEN;

	/* Wait for finishing */
	while (AT91C_BASE_AES->AES_TCR) {
	}
	while (!(AT91C_BASE_AES->AES_ISR & AT91C_AES_DATRDY)) {
	}

	/*
	 * Get result - write MIC before payload, so CTR encryption in ZigBee
	 * can be done in one step (the MIC is encrypted with counter value 0,
	 * the payload with 1,2,...)
	 */
	memcpy(buf + micoff,
			(void *)(AT91C_BASE_AES->AES_ODATAxR),
			AES_BLOCKSIZE);
}
Exemplo n.º 4
0
double bst_compute_114_block_unroll_8( void*_bst_obj, double* p, double* q, size_t nn ) {
    segments_t* mem = (segments_t*) _bst_obj;
    int n;
    int i, l, r, j;
    double t, t_min, w_cur;
    int r_min;
    double* e = mem->e, *w = mem->w;
    int* root = mem->r;
    // initialization
    mem->n = nn;
    n = nn; // subtractions with n potentially negative. say hello to all the bugs
    for( i = 0; i < n+1; i++ ) {
        e[IDX(i,i)] = q[i];
        w[IDX(i,i)] = q[i];
    }

    int ib;

    // compute bottom right triangle NBxNB (i.e. bottom NB rows)
    for (i = n-1; (i >= 0) && (i > (n-NB)); --i) {
        for (j = i+1; j < n+1; ++j) {
            e[IDX(i,j)] = INFINITY;
            w[IDX(i,j)] = w[IDX(i,j-1)] + p[j-1] + q[j];
            FULL_BLOCK(i, j, r, i, j);
            /*
            for (r=i; r<j; ++r) {
                t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                if (t < e[IDX(i,j)]) {
                    e[IDX(i,j)] = t;
                    root[IDX(i,j)] = r;
                }
            }
            */
        }
    }

    // compute the remaining rows
    // printf("Rest of rows: i=%d\n", i);
    for (; i >= 0; --i) {
        // First, the starting NB values in this row are computed.
        // This corresponds to completing the NBxNB triangle right down from (i,i)
        for (j = i+1; j < (i+NB); ++j) {
            e[IDX(i,j)] = INFINITY;
            w[IDX(i,j)] = w[IDX(i,j-1)] + p[j-1] + q[j];
            FULL_BLOCK(i, j, r, i, j);
            /*
            for (r=i; r<j; ++r) {
                t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                if (t < e[IDX(i,j)]) {
                    e[IDX(i,j)] = t;
                    root[IDX(i,j)] = r;
                }
            }
            */
        }

        // Now we compute the rest of the row, but do updates in chunk of NB's.
        // Since we now have the first NB values in this row, we can compute
        // the first NB iterations of the r-loop for all the remaining values
        // in this row.
        // (this needs to be seperated from the loop afterwards since we also do
        //  initialization to INFINITY))
        for (; j < (n+1); ++j) {
            e[IDX(i,j)] = INFINITY;
            w[IDX(i,j)] = w[IDX(i,j-1)] + p[j-1] + q[j];
            FULL_BLOCK(i, j, r, i, i+NB);
            /*
            for (r=i; r < (i+NB); ++r) {
                t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                if (t < e[IDX(i,j)]) {
                    e[IDX(i,j)] = t;
                    root[IDX(i,j)] = r;
                }
            }
            */
        }

        // We now continue to update the values in this row in chunks of NB
        // as long as possible.
        for (ib = i+NB; (ib+NB) < (n+1); ib += NB) {
            //printf("got in here for i=%d\n", i);

            // Again we start by finishing computing the next NB values of
            // row 'i'. The last values needed for that are from the triangle
            // in down right from (ib,ib).
            for (j = (ib+1); j < (ib+NB); ++j) {
                FULL_BLOCK(i, j, r, ib, j);
                /*
                for (r=ib; r<j; ++r) {
                    t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                    if (t < e[IDX(i,j)]) {
                        e[IDX(i,j)] = t;
                        root[IDX(i,j)] = r;
                    }
                }
                */
            }

            // Now, having NB new values in row 'i', we compute the next NB
            // r-iterations for the remaining values in row 'i'.
            // THIS IS THE MAIN LOOP

            for (; j < (n+1); ++j) {
#if (NB != 8)
#error NB must be 8
#endif

#if 1
                double t1, t2, t3, t4, t5, t6, t7, t8;
                double t12, t34, t56, t78;
                double t1234, t5678;
                int r12, r34, r56, r78, r1234, r5678;

                double w_cur = w[IDX(i,j)];
                int idx_i_ib = IDX(i,ib);

                t1 = e[idx_i_ib+0] + e[IDX(ib+1,j)] + w_cur;
                t2 = e[idx_i_ib+1] + e[IDX(ib+2,j)] + w_cur;
                t3 = e[idx_i_ib+2] + e[IDX(ib+3,j)] + w_cur;
                t4 = e[idx_i_ib+3] + e[IDX(ib+4,j)] + w_cur;
                t5 = e[idx_i_ib+4] + e[IDX(ib+5,j)] + w_cur;
                t6 = e[idx_i_ib+5] + e[IDX(ib+6,j)] + w_cur;
                t7 = e[idx_i_ib+6] + e[IDX(ib+7,j)] + w_cur;
                t8 = e[idx_i_ib+7] + e[IDX(ib+8,j)] + w_cur;

                /*
                printf("i=%d, j=%d, ib=%d\n", i, j, ib);
                printf("T1=%.3lf, "
                       "T2=%.3lf, "
                       "T3=%.3lf, "
                       "T4=%.3lf, "
                       "T5=%.3lf, "
                       "T6=%.3lf, "
                       "T7=%.3lf, "
                       "T8=%.3lf, \n",
                       t1, t2, t3, t4, t5, t6, t7);
                       */

                if (t1 < t2) { t12 = t1; r12 = ib+0; }
                else         { t12 = t2; r12 = ib+1; }
                if (t3 < t4) { t34 = t3; r34 = ib+2; }
                else         { t34 = t4; r34 = ib+3; }
                if (t5 < t6) { t56 = t5; r56 = ib+4; }
                else         { t56 = t6; r56 = ib+5; }
                if (t7 < t8) { t78 = t7; r78 = ib+6; }
                else         { t78 = t8; r78 = ib+7; }
                if (t12 < t34) { t1234 = t12; r1234 = r12; }
                else           { t1234 = t34; r1234 = r34; }
                if (t56 < t78) { t5678 = t56; r5678 = r56; }
                else           { t5678 = t78; r5678 = r78; }
                if (t1234 < t5678) { t = t1234; r = r1234; }
                else               { t = t5678; r = r5678; }

                if (t < e[IDX(i,j)]) {
                    e[IDX(i,j)] = t;
                    root[IDX(i,j)] = r;
                }
#else
                //FULL_BLOCK(i, j, r, ib, ib+NB);
                printf("i=%d, j=%d, ib=%d\n", i, j, ib);
                for (r=ib; r<(ib+NB); ++r) {
                    t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                    printf("T%d=%.3lf, ", r-ib+1, t);
                    if (t < e[IDX(i,j)]) {
                        e[IDX(i,j)] = t;
                        root[IDX(i,j)] = r;
                    }
                }
                printf("\n");
#endif
            }
        }

        // There are less than NB elements remaining in row 'i'. The values
        // missing come from the triangle down right of (ib,ib)
        for (j = (ib+1); j < (n+1); ++j) {
            FULL_BLOCK(i, j, r, ib, j);
            /*
            for (r=ib; r<j; ++r) {
                t = e[IDX(i,r)] + e[IDX(r+1,j)] + w[IDX(i,j)];
                if (t < e[IDX(i,j)]) {
                    e[IDX(i,j)] = t;
                    root[IDX(i,j)] = r;
                }
            }
            */
        }
    }

    return e[IDX(0,n)];
}