pike.git / src / post_modules / Nettle / hash.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hash.cmod:150:    INT32 i = p->num_inherits;    while( i-- )    {    if( p->inherits[i].prog->id == PROG_STDIO_FD_ID ||    p->inherits[i].prog->id == PROG_STDIO_FD_REF_ID )    return 1;    }    return 0;    }    -  /*! @decl string(0..255) hash(Stdio.File|Stdio.Buffer|String.Buffer|System.Memory source, void|int bytes) +  /*! @decl string(0..255) hash(Stdio.File|Stdio.Buffer|String.Buffer|System.Memory source, void|int(0..) bytes)    *!    *! Works as a (faster) shortcut for e.g.    *! @expr{State()->update(Stdio.read_file(file))->digest()@},    *! where State is the hash state class corresponding to this    *! Hash.    *!    *! @param bytes    *! The number of bytes of the file object @[file] that should be    *! hashed. Negative numbers are ignored and the whole file is    *! hashed.    *!    *! @seealso    *! @[Stdio.File], @[State()->update()] and    *! @[State()->digest()].    */ -  PIKEFUN string(0..255) hash(object in, void|int bytes) +  PIKEFUN string(0..255) hash(object in, void|int(0..) bytes)    optflags OPT_EXTERNAL_DEPEND;    {    void *ctx;    size_t len;    int fd;    char *read_buffer;    PIKE_STAT_T st;    struct pike_string *out;    const struct nettle_hash *meta = THIS->meta;   
pike.git/src/post_modules/Nettle/hash.cmod:259:    *! Password hashing function in @[crypt_md5()]-style.    *!    *! Implements the algorithm described in    *! @url{http://www.akkadia.org/drepper/SHA-crypt.txt@}.    *!    *! This is the algorithm used by @tt{crypt(2)@} in    *! methods @tt{$5$@} (SHA256) and @tt{$6$@} (SHA512).    *!    *! The @[password] memory will be cleared before released.    *! +  *! Rounds will never be set to less than 1000. If @[rounds] is 0 +  *! it will be set to 5000. +  *!    *! @seealso    *! @[crypt_md5()]    */    PIKEFUN string(0..127) crypt_hash(string(0..255) password,    string(0..255) salt, int rounds)    {    struct pike_string *res;    const struct nettle_hash *meta = THIS->meta;    void *ctx;    uint8_t *abcbuf;
pike.git/src/post_modules/Nettle/hash.cmod:512:    THREADS_ALLOW();    meta->update(ctx, data->len, (const uint8_t *)data->str);    THREADS_DISALLOW();    } else {    meta->update(ctx, data->len, (const uint8_t *)data->str);    }       push_object(this_object());    }    -  /*! @decl string(0..255) digest(int|void length) +  /*! @decl string(0..255) digest(int(0..)|void length)    *!    *! Generates a digest, and resets the hashing contents.    *!    *! @param length    *! If the length argument is provided, the digest is truncated    *! to the given length.    *!    *! @returns    *! The digest.    */ -  PIKEFUN string(0..255) digest(int|void arg) +  PIKEFUN string(0..255) digest(int(0..)|void arg)    {    const struct nettle_hash *meta;    struct pike_string *digest;    unsigned length;       meta = GET_META(Pike_fp->current_object);       if (!THIS->ctx || !meta)    Pike_error("State not properly initialized.\n");       if (!arg)    length = meta->digest_size;    else    { -  if (TYPEOF(*arg) != PIKE_T_INT) -  Pike_error("Bad argument type.\n"); +     if (arg->u.integer < 0)    Pike_error("Invalid length, must be positive.\n");    if ((unsigned)arg->u.integer > meta->digest_size)    Pike_error("Unsupported digest length.\n");       length = arg->u.integer;    }       digest = begin_shared_string(length);    meta->digest(THIS->ctx, length, (uint8_t *)digest->str);