Exemplo n.º 1
0
inline static
void compute_two_stage_sha1_hash(const char *password, size_t pass_len,
                                 uint8 *hash_stage1, uint8 *hash_stage2)
{
  /* Stage 1: hash password */
  compute_sha1_hash(hash_stage1, password, pass_len);

  /* Stage 2 : hash first stage's output. */
  compute_sha1_hash(hash_stage2, (const char *) hash_stage1, SHA1_HASH_SIZE);
}
int ChordNode::delete_file(Command command){
    
    int hash_value = compute_sha1_hash(command.key_and_value.first.c_str(), ring_size);
    #ifdef DEBUG
    cout << "Hash value :" << hash_value << endl;
    #endif

    int position;
    if (id < predecessor && ((hash_value > id && hash_value > predecessor) || hash_value < id) ){
        /* Case: File is betwen the first and the last node od the ring */
        
        position = search_in_a_vector_of_files(files, hash_value);
        if(position == -1 ){
            return 0;
        }else{
            files.erase(files.begin() + position);
            return 1;
        }
    }else if (hash_value < id && hash_value > predecessor) {
        /* Typical case */

        position = search_in_a_vector_of_files(files, hash_value);
        if(position == -1 ){
            return 0;
        }else{
            files.erase(files.begin() + position);
            return 1;
        }

    } else return 0;
}
int ChordNode::insert(Command command){

    /* Calclulate hash value of the data to be inserted */
    int hash_value = compute_sha1_hash(command.key_and_value.first.c_str(), ring_size);
#ifdef DEBUG
    cout << "Hash value :" << hash_value << endl;
#endif
    
    int position;
    if (id < predecessor && ((hash_value > id && hash_value > predecessor) || hash_value < id)){
        /* Case: File is betwen the first and the last node od the ring */

        position = search_in_a_vector_of_files(files, hash_value);
        if(position == -1 ){
            files.push_back(std::make_pair(hash_value, command.key_and_value.second));
        } else {
            /* If file exists, update its value */
            files.at(position).second = command.key_and_value.second;
        }
        return 1;

    } else if (hash_value < id && hash_value > predecessor) {
        /* Case: Typical case */
        position = search_in_a_vector_of_files(files, hash_value);
        if(position == -1 ) {
            files.push_back(std::make_pair(hash_value, command.key_and_value.second));
        } else {
            /* If file exists, update its value */
            files.at(position).second = command.key_and_value.second;
        }
        return 1;

    } else return 0;

}
Exemplo n.º 4
0
my_bool
check_scramble(const uchar *scramble_arg, const char *message,
               const uint8 *hash_stage2)
{
  uint8 buf[SHA1_HASH_SIZE];
  uint8 hash_stage2_reassured[SHA1_HASH_SIZE];

  /* create key to encrypt scramble */
  compute_sha1_hash_multi(buf, message, SCRAMBLE_LENGTH,
                          (const char *) hash_stage2, SHA1_HASH_SIZE);
  /* encrypt scramble */
  my_crypt((char *) buf, buf, scramble_arg, SCRAMBLE_LENGTH);

  /* now buf supposedly contains hash_stage1: so we can get hash_stage2 */
  compute_sha1_hash(hash_stage2_reassured, (const char *) buf, SHA1_HASH_SIZE);

  return MY_TEST(memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE));
}