~7-luca/skylable/master

« back to all changes in this revision

Viewing changes to server/src/common/hashfs.c

  • Committer: Alberto Wu
  • Date: 2015-10-29 16:39:50 UTC
  • Revision ID: git-v1:4d0837a887d92ed148e87a6e7bb7f4096046dc98
Allow building with valgrind hints (--enable-vghints)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2794
2794
        /* non-blocking pseudo-random bytes, i.e. we don't want to block or deplete
2795
2795
         * entropy as we only need a unique sequence of bytes, not a secret one as
2796
2796
         * it is sent in plaintext anyway, and signed with an HMAC */
2797
 
        if(sxi_rand_pseudo_bytes(rndbin, sizeof(rndbin)) == -1) {
 
2797
        if(sxi_rand_pseudo_bytes(rndbin, sizeof(rndbin))) {
2798
2798
            /* can also return 0 or 1 but that doesn't matter here */
2799
2799
            WARN("Cannot generate random bytes");
2800
2800
            msg_set_reason("Failed to generate random string");
8799
8799
    /* non-blocking pseudo-random bytes, i.e. we don't want to block or deplete
8800
8800
     * entropy as we only need a unique sequence of bytes, not a secret one as
8801
8801
     * it is sent in plaintext anyway, and signed with an HMAC */
8802
 
    if (sxi_rand_pseudo_bytes(rnd, sizeof(rnd)) == -1) {
 
8802
    if (sxi_rand_pseudo_bytes(rnd, sizeof(rnd))) {
8803
8803
        /* can also return 0 or 1 but that doesn't matter here */
8804
8804
        WARN("Cannot generate random bytes");
8805
8805
        return FAIL_EINTERNAL;
12542
12542
#define MAX_UID_GEN_TRIES     100
12543
12543
/* TODO: Find a better way to generate unique UIDs */
12544
12544
rc_ty sx_hashfs_generate_uid(sx_hashfs_t *h, uint8_t *uid) {
12545
 
    unsigned int i = 0;
 
12545
    unsigned int i;
12546
12546
 
12547
12547
    if(!uid) {
12548
12548
        NULLARG();
12554
12554
        return FAIL_LOCKED;
12555
12555
    }
12556
12556
 
12557
 
    sxi_rand_pseudo_bytes(uid + AUTH_CID_LEN, AUTH_UID_LEN - AUTH_CID_LEN);
12558
 
    while(sx_hashfs_get_user_info(h, uid, NULL, NULL, NULL, NULL, NULL) != ENOENT && i < MAX_UID_GEN_TRIES) {
12559
 
        i++;
12560
 
        sxi_rand_pseudo_bytes(uid + AUTH_CID_LEN, AUTH_UID_LEN - AUTH_CID_LEN);
 
12557
    for(i = 0; i < MAX_UID_GEN_TRIES; i++) {
 
12558
        if(sxi_rand_pseudo_bytes(uid + AUTH_CID_LEN, AUTH_UID_LEN - AUTH_CID_LEN))
 
12559
            continue;
 
12560
        if(sx_hashfs_get_user_info(h, uid, NULL, NULL, NULL, NULL, NULL) == ENOENT)
 
12561
            break;
12561
12562
    }
12562
12563
 
12563
12564
    if(i == MAX_UID_GEN_TRIES) {
14444
14445
    rc_ty ret;
14445
14446
 
14446
14447
    if(random_challenge) {
14447
 
        if(sxi_rand_pseudo_bytes(c->challenge, sizeof(c->challenge)) == -1) {
 
14448
        if(sxi_rand_pseudo_bytes(c->challenge, sizeof(c->challenge))) {
14448
14449
            WARN("Cannot generate random bytes");
14449
14450
            msg_set_reason("Failed to generate random nounce");
14450
14451
            return FAIL_EINTERNAL;