static int add_preamble(struct file *fp, unsigned char *key, int len) { int rc; unsigned char *keyHash = NULL; mm_segment_t fs; keyHash = key_to_hash(key); if(!keyHash){ printk("Error in hashing userland key while adding preamble\n"); rc = -ENOKEY; goto out; } fs=get_fs(); set_fs(get_ds()); rc = fp->f_op->write(fp,keyHash,len,&fp->f_pos); if(rc < 0){ printk("Failed to store key while encryption\n"); set_fs(fs); rc= -EIO; goto out; } set_fs(fs); out: if(keyHash) kfree(keyHash); return rc; }
void* hash_add(void* hash_table, const void* key, void* hash_node, void* cache_node, void* pool_handle) { hash_t* hash = (hash_t*) hash_table; u32 hash_code = key_to_hash(hash, key); if (hash_code >= hash->max_buckets) { DEBUG_ERROR("hash key is invalid: %d", hash_code); return NULL; } node_t* node = (node_t*) hash_node; if (node == NULL) { node = (node_t*) pool_get_element(pool_handle, POOL_TYPE_NODE_T); node->usr_data = (hash_data_t*) pool_get_element(pool_handle, POOL_TYPE_HASH_DATA_T); ((hash_data_t*) node->usr_data)->key = pool_get_element(pool_handle, POOL_TYPE_KEY_SIZE); } memset(((hash_data_t*) node->usr_data)->key, 0, hash->key_size); memcpy(((hash_data_t*) node->usr_data)->key, key, hash->key_size); ((hash_data_t*) node->usr_data)->cache_node_ptr = cache_node; node->next_node = NULL; node->previous_node = NULL; bucket_t* bucket = &(hash->bucket_list[hash_code]); if (bucket->list == NULL) { bucket->list = (list_t*) pool_get_element(pool_handle, POOL_TYPE_LIST_T); bucket->list_count = 0; list_init(bucket->list); } list_push_back(bucket->list, node); bucket->list_count++; hash->entry_count++; DEBUG_INFO("Add hash key successfully,hash_code:%d", hash_code); return node; }
void static attribute_slot(t_hill *hill, t_room *room) { unsigned int hash; hash = key_to_hash(room->name, ft_strlen(room->name)) % (10 * hill->len); if (hill->flags & F_DEBUGEN) ft_printf("Room '%s' has hash: {{red;u}}0x%.2X{{eoc;}}\n", room->name, hash); if (room->command == COMMAND_START) hill->start = room; else if (room->command == COMMAND_END) hill->end = room; room->visited = false; hill->rooms[hash] = room; }
static int verify_preamble(struct file *fp, unsigned char *key, int len) { int rc; unsigned char *verify_key= NULL; unsigned char *keyHash= NULL; mm_segment_t fs; keyHash = key_to_hash(key); if(!keyHash){ printk("Error in hashing userland key while verifying preamble\n"); rc = -ENOKEY; goto out; } verify_key=kmalloc(len,GFP_KERNEL); if(IS_ERR(verify_key)){ printk("Error in allocating memory to temp Key\n "); rc = -PTR_ERR(verify_key); goto out; } fs=get_fs(); set_fs(get_ds()); rc = fp->f_op->read(fp,verify_key,len,&fp->f_pos); if(rc < 0){ printk("Failed to read key while decryption\n"); set_fs(fs); rc= -EIO; goto out; } set_fs(fs); rc = memcmp((void*)verify_key,(void*)keyHash,len); if(rc != 0) { printk("Key mismatched \n"); rc= -EKEYREJECTED; } out: if(verify_key) kfree(verify_key); if(keyHash) kfree(keyHash); return rc; }
void* hash_del(void* hash_table, const void* key, void* hash_node, void* pool_handle) { hash_t* hash = (hash_t*) hash_table; u32 hash_code = key_to_hash(hash, key); if (unlikely(hash_code >= hash->max_buckets)) { DEBUG_ERROR("hash key is invalid: %d", hash_code); return NULL; } bucket_t* bucket = &(hash->bucket_list[hash_code]); if (unlikely(bucket->list == NULL)) { DEBUG_ERROR("delete hash fail: hash list haven't element"); return NULL; } else { node_t* node = (node_t*) hash_node; list_remove(bucket->list, node); } bucket->list_count--; hash->entry_count--; return hash_node; }
void* hash_find(void* hash_table, const void* key) { hash_t *hash = (hash_t*) hash_table; u32 hash_code = key_to_hash(hash, key); if (unlikely(hash_code >= hash->max_buckets)) { DEBUG_ERROR("hash_find failed: hash key[%d] is invalid", hash_code); return NULL; } bucket_t* bucket = &(hash->bucket_list[hash_code]); node_t* node = NULL; if (likely(bucket->list)) { node = bucket->list->head_node; while (node) { if (!hash->kcmp(key, ((hash_data_t*) node->usr_data)->key)) { break; } node = node->next_node; } } return node; }
unsigned long UniqueString::hash() const { return key_to_hash(string()); }