Exemplo n.º 1
0
/**
 * @brief xor hash the file given
 *
 * @see
 * @note
 * @author auxten  <*****@*****.**>
 * @date 2011-8-1
 **/
unsigned xor_hash_file(unsigned value, FILE * fd, off_t * off, size_t * count,
        u_char * buf)
{
    fseeko(fd, *off, SEEK_SET);
    if (FAIL_CHECK(*count != fread(buf, sizeof(char), *count, fd)))
    {
        GKOLOG(FATAL, "fread error");
    }
    ///fprintf(stderr, "#######################buf: %s\n", buf);
    return xor_hash(buf, *count, value);
}
Exemplo n.º 2
0
void printChosen(char* s, unsigned size, struct information info) {
    printf("Length: %u bytes\n", size-1);
    if(info.hex) {
        if(info.doXor)
            printf("XOR: 0x%02x\n", xor_hash(s, size));
        if(info.doCrc16)
            printf("CRC-16: 0x%04x\n", crc_16(s, size));
        if(info.doCrc32)
            printf("CRC-32: 0x%08x\n", crc_32(s, size));
    } else {
        if(info.doXor)
            printf("XOR: %u\n", xor_hash(s, size));
        if(info.doCrc16)
            printf("CRC-16: %u\n", crc_16(s, size));
        if(info.doCrc32)
            printf("CRC-32: %u\n", crc_32(s, size));
    }
    if(info.doMd5) {
        printf("MD5: ");
        printMD5(s, size);
        printf("\n");
    }
}
Exemplo n.º 3
0
/**
 * @brief generate snap file path with requested localpath and requested remote uri
 *
 * @see
 * @note
 *     return the hash result from xor_hash(uri, strlen(uri), 0)
 *     the snap file path is stored in snap_fpath
 * @return  0 for error
 *          uri_hash for succ
 * @author auxten  <*****@*****.**>
 * @date 2011-8-1
 **/
unsigned gen_snap_fpath(char *snap_fpath, const char * localpath,
        const char * uri)
{
    if (!snap_fpath || !localpath || !uri)
    {
        GKOLOG(FATAL, "%s %s passed NULL p", __FILE__, __func__);
        return 0;
    }

    char out_path[MAX_PATH_LEN] = {'\0'};
    strncpy(out_path, localpath, MAX_PATH_LEN);
    inplace_strip_tailing_slash(out_path);

    if (!cwd_path_to_abs_path(snap_fpath, out_path))
    {
        GKOLOG(WARNING, "cwd_path_to_abs_path failed '%s' '%s'", snap_fpath,
                out_path);
        return 0;
    }
    /** cut the tailing file in path **/
    if (!(path_type(snap_fpath) & GKO_DIR))
    {
        int idx;
        if ((idx = get_base_name_index(NULL, snap_fpath)) < 0)
        {
            GKOLOG(WARNING, "gen_snap_fpath failed '%s' '%s' '%s'", snap_fpath,
                    out_path, uri);
            return 0;
        }
        *(snap_fpath + idx) = '\0';
    }

    int snap_fpath_len = strlen(snap_fpath);
    unsigned uri_hash = xor_hash(uri, strlen(uri), 0);
    snprintf(snap_fpath + snap_fpath_len, MAX_PATH_LEN - snap_fpath_len,
            "/%s%u", GKO_SNAP_FILE, uri_hash);

    GKOLOG(NOTICE, "gko.snap_fpath: '%s'", snap_fpath);
    return uri_hash;
}
Exemplo n.º 4
0
/**
 * @brief check if the fnv check sum is OK
 *
 * @see
 * @note
 * @author auxten  <*****@*****.**>
 * @date 2011-8-1
 **/
char digest_ok(void * buf, s_block_t * b)
{
    return (xor_hash(buf, b->size, 0) == b->digest);
}