Esempio n. 1
0
void read_test()
{
	MPI_Barrier_Sync();

	root_printf("Test %d: Random concurrent read test\n", testno);
	if (rank == 0) {
		create_and_prep_dir();
		create_files(NULL, operated_entries);
		sync_mmap();
	}

	MPI_Barrier_Sync();

	if (rank) {
		random_read(operated_entries / 2);
	}
	
	MPI_Barrier_Sync();

	sleep(2);

	if (rank == 0) {
                verify_dirents();
        }

	MPI_Barrier_Sync();

	if (rank == 0)
		destroy_dir();

	testno++;

}
Esempio n. 2
0
File: main.c Progetto: wuwx/simba
static int test_read(struct harness_t *harness_p)
{
    uint32_t random[16];
    int i;

    for (i = 0; i < 16; i++) {
        random[i] = random_read();
    }

    for (i = 0; i < 16; i++) {
        std_printf(FSTR("read: 0x%08lx\r\n"), (unsigned long)random[i]);
    }

    return (0);
}
stream_t *stream_create(const char *topic_patt_str)
{
    stream_t *stream;

    if (NULL == (stream = (stream_t *)calloc(sizeof(stream_t), 1)))
        goto fail;
    if (NULL == (stream->topic_patt = topic_create_from_string(topic_patt_str)))
        goto fail;
    if (NULL == (stream->rsp_q = tailq_create()))
        goto fail;
    if (NULL == (stream->topicstr = strdup(topic_patt_str)))
        goto fail;
    stream->timeoutS = DEFAULT_STREAM_TIMEOUT_S;
    stream->streamid = g_srvctx.streamid++;

    random_read(stream->seckey, STREAM_SECKEY_SIZE);

    return stream;
fail:
    stream_destroy(stream);
    return NULL;
}
Esempio n. 4
0
strbuf *ssh_rsakex_encrypt(RSAKey *rsa, const ssh_hashalg *h, ptrlen in)
{
    mp_int *b1, *b2;
    int k, i;
    char *p;
    const int HLEN = h->hlen;

    /*
     * Here we encrypt using RSAES-OAEP. Essentially this means:
     * 
     *  - we have a SHA-based `mask generation function' which
     *    creates a pseudo-random stream of mask data
     *    deterministically from an input chunk of data.
     * 
     *  - we have a random chunk of data called a seed.
     * 
     *  - we use the seed to generate a mask which we XOR with our
     *    plaintext.
     * 
     *  - then we use _the masked plaintext_ to generate a mask
     *    which we XOR with the seed.
     * 
     *  - then we concatenate the masked seed and the masked
     *    plaintext, and RSA-encrypt that lot.
     * 
     * The result is that the data input to the encryption function
     * is random-looking and (hopefully) contains no exploitable
     * structure such as PKCS1-v1_5 does.
     * 
     * For a precise specification, see RFC 3447, section 7.1.1.
     * Some of the variable names below are derived from that, so
     * it'd probably help to read it anyway.
     */

    /* k denotes the length in octets of the RSA modulus. */
    k = (7 + mp_get_nbits(rsa->modulus)) / 8;

    /* The length of the input data must be at most k - 2hLen - 2. */
    assert(in.len > 0 && in.len <= k - 2*HLEN - 2);

    /* The length of the output data wants to be precisely k. */
    strbuf *toret = strbuf_new_nm();
    int outlen = k;
    unsigned char *out = strbuf_append(toret, outlen);

    /*
     * Now perform EME-OAEP encoding. First set up all the unmasked
     * output data.
     */
    /* Leading byte zero. */
    out[0] = 0;
    /* At position 1, the seed: HLEN bytes of random data. */
    random_read(out + 1, HLEN);
    /* At position 1+HLEN, the data block DB, consisting of: */
    /* The hash of the label (we only support an empty label here) */
    {
        ssh_hash *s = ssh_hash_new(h);
        ssh_hash_final(s, out + HLEN + 1);
    }
    /* A bunch of zero octets */
    memset(out + 2*HLEN + 1, 0, outlen - (2*HLEN + 1));
    /* A single 1 octet, followed by the input message data. */
    out[outlen - in.len - 1] = 1;
    memcpy(out + outlen - in.len, in.ptr, in.len);

    /*
     * Now use the seed data to mask the block DB.
     */
    oaep_mask(h, out+1, HLEN, out+HLEN+1, outlen-HLEN-1);

    /*
     * And now use the masked DB to mask the seed itself.
     */
    oaep_mask(h, out+HLEN+1, outlen-HLEN-1, out+1, HLEN);

    /*
     * Now `out' contains precisely the data we want to
     * RSA-encrypt.
     */
    b1 = mp_from_bytes_be(make_ptrlen(out, outlen));
    b2 = mp_modpow(b1, rsa->exponent, rsa->modulus);
    p = (char *)out;
    for (i = outlen; i--;) {
	*p++ = mp_get_byte(b2, i);
    }
    mp_free(b1);
    mp_free(b2);

    /*
     * And we're done.
     */
    return toret;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
    srand(time(0));
    
    std::string filename;
    std::string garbage;
    bool runGarbage = false;
    bool write = false;
    bool timing = true;
    
    int c;
    while ((c = getopt(argc, argv, "f:g:wtd")) != EOF)
        switch (c)
    {
        case 'f': filename = optarg; break;
        case 't': timing = true; break;
        case 'g': garbage = optarg; runGarbage=true; break;
        case 'w': write = true; break;
        case 'd': debug = true; break;
        case '?': return 1;
    }
    
    if (filename.empty()){
        fprintf(stderr, "-f <filename> is not set\n");
        return 1;
    }
    
    // Remember: mod(size, parallel files) must be zero
    if (write) {
        writeFile(filename.c_str(), 250000000);
    }
    std::streampos size = getSize(filename.c_str());
    if (size < 0) {
        fprintf(stderr, "File do not exists: %s\n", filename.c_str());
        return 1;
    }
    
    if (garbage.empty())
        fprintf(stderr, "-g <filename> is not set - Not running garbage file\n");
    
    std::streampos sizeGarbage;
    if (runGarbage){
        sizeGarbage = getSize(garbage.c_str());
        if (sizeGarbage < 0) {
            fprintf(stderr, "File do not exists: %s\n", garbage.c_str());
            return 1;
        }
    }
    
    std::vector<uint32_t> blocksizes;
    
    blocksizes.push_back(1024);
    blocksizes.push_back(4096);
    blocksizes.push_back(16384);
    
    
    std::vector<uint32_t>::const_iterator bs;
    
    for(bs=blocksizes.begin(); bs!=blocksizes.end(); bs++){

      //* Run parallel reads
      for (int i = 1; i<=32; i = i<<1){
	// Clear buffers
	if (runGarbage){
	  if(debug) printf("Reading garbage...\n");
	  read(garbage.c_str(), sizeGarbage, 1, sizeof(uint32_t));
	  system("sync; echo 3 > /proc/sys/vm/drop_caches");    
	}
        
	// Read file
	//printf("Reading with %d concurrent files open... bs: %d \n", i, *bs);
	double t = read(filename.c_str(), size, i, *bs);
	printf("%2d files(%d): %.6f sec\n", i, *bs, t);
      }
      //*/
      
      //* Run random read
      if (runGarbage){
	if(debug) printf("Reading garbage...\n");
	read(garbage.c_str(), sizeGarbage, 1, sizeof(uint32_t));
	system("sync; echo 3 > /proc/sys/vm/drop_caches");    
      }
      
      double t = random_read(filename.c_str(), size, *bs);
      printf("random block(%d): %.6f sec\n", *bs, t);
      //*/
    }
}