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

version» Context lines:

pike.git/src/post_modules/Nettle/hash.cmod:55:      /*! @class HashInfo    *!    *! Represents information about a hash algorithm, such as    *! name, digest size, and internal block size.    */   PIKECLASS HashInfo   {    CVAR const struct nettle_hash *meta;    -  /*! @decl string name(void) +  /*! @decl string(0..255) name(void)    *!    *! Returns a human readable name for the algorithm.    */ -  PIKEFUN string name() +  PIKEFUN string(0..255) name()    optflags OPT_TRY_OPTIMIZE;    {    if (!THIS->meta)    Pike_error("HashInfo not properly initialized.\n");       push_text(THIS->meta->name);    }    -  /*! @decl string digest_size(void) +  /*! @decl int(0..) digest_size(void)    *!    *! Returns the size of a hash digests.    */ -  PIKEFUN int digest_size() +  PIKEFUN int(0..) digest_size()    optflags OPT_TRY_OPTIMIZE;    {    if (!THIS->meta)    Pike_error("HashInfo not properly initialized.\n");       push_int(THIS->meta->digest_size);    }    -  /*! @decl string block_size(void) +  /*! @decl int(0..) block_size(void)    *!    *! Returns the internal block size of the hash algorithm.    */ -  PIKEFUN int block_size() +  PIKEFUN int(0..) block_size()    optflags OPT_TRY_OPTIMIZE;    {    if (!THIS->meta)    Pike_error("HashInfo not properly initialized.\n");       push_int(THIS->meta->block_size);    }       -  /*! @decl string hash(string data) +  /*! @decl string(0..255) hash(string data)    *!    *! Works as a (faster) shortcut for    *! @expr{HashState()->update(data)->digest()@}, where HashState is    *! the hash state class corresponding to this HashInfo.    *!    *! @seealso    *! @[HashState()->update()] and @[HashState()->digest()].    */ -  PIKEFUN string hash(string in) +  PIKEFUN string(0..255) hash(string in)    optflags OPT_TRY_OPTIMIZE;    {    void *ctx;    struct pike_string *out;    unsigned digest_length;    const struct nettle_hash *meta = THIS->meta;       if (!meta)    Pike_error("HashInfo not properly initialized.\n");    NO_WIDE_STRING(in);
pike.git/src/post_modules/Nettle/hash.cmod:139:    }       digest_length = meta->digest_size;    out = begin_shared_string(digest_length);    meta->digest(ctx, digest_length, (uint8_t *)out->str);       pop_n_elems(args);    push_string(end_shared_string(out));    }    -  /*! @decl string hash(Stdio.File file, void|int bytes) +  /*! @decl string(0..255) hash(Stdio.File file, void|int bytes)    *!    *! Works as a (faster) shortcut for    *! @expr{HashState()->update(Stdio.read_file(file))->digest()@},    *! where HashState is the hash state class corresponding to this    *! HashInfo.    *!    *! @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], @[HashState()->update()] and    *! @[HashState()->digest()].    */ -  PIKEFUN string hash(object in, void|int bytes) +  PIKEFUN string(0..255) hash(object in, void|int bytes)    optflags OPT_EXTERNAL_DEPEND;    {    void *ctx;    int len, fd;    char *read_buffer;    PIKE_STAT_T st;    struct pike_string *out;    const struct nettle_hash *meta = THIS->meta;       if (!meta)
pike.git/src/post_modules/Nettle/hash.cmod:253:       static inline void b64enc(char *dest, int a, int b, int c, int sz)    {    unsigned int bitbuf = a | (b << 8) | (c << 16);    while (sz--) {    *(dest++) = b64tab[bitbuf & 63];    bitbuf >>= 6;    }    }    -  /*! @decl string crypt_hash(string password, string salt, int rounds) +  /*! @decl string(0..255) crypt_hash(string password, string salt, rounds)    *!    *! 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).    *!    *! @seealso    *! @[crypt_md5()]    */ -  PIKEFUN string crypt_hash(string password, string salt, int rounds) +  PIKEFUN string(0..255) crypt_hash(string password, string salt, int rounds)    {    struct pike_string *res;    const struct nettle_hash *meta = THIS->meta;    void *ctx;    uint8_t *abcbuf;    uint8_t *dpbuf;    uint8_t *dsbuf;    -  char *p; -  char *s; +  unsigned char *p; +  unsigned char *s;    int plen;    int slen;    int dsz = meta->digest_size;       int i;    int r;       int a, b, c;       if (!rounds) rounds = 5000;
pike.git/src/post_modules/Nettle/hash.cmod:307:    abcbuf = (uint8_t *)alloca(meta->digest_size * 3);    if (!abcbuf)    SIMPLE_OUT_OF_MEMORY_ERROR("crypt_hash", meta->digest_size * 3);       dpbuf = abcbuf + meta->digest_size;    dsbuf = dpbuf + meta->digest_size;       /* NB: We use these to allow the compiler to    * avoid dereferencing at every step.    */ -  p = password->str; +  p = (unsigned char*)password->str;    plen = password->len; -  s = salt->str; +  s = (unsigned char*)salt->str;    slen = salt->len;    if (slen > 16) slen = 16;    dsz = meta->digest_size;       /* NB: We allocate the result here to avoid throwing away all the work    * on out of memory at the end.    */    if (dsz == 32) {    /* 4 * (30/3) + 3 */    res = begin_shared_string(43);
pike.git/src/post_modules/Nettle/hash.cmod:502:    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 digest(int|void length) +  /*! @decl string(0..255) digest(int|void length)    *!    *! Generates a digests, 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 digest(int|void arg) +  PIKEFUN string(0..255) digest(int|void arg)    {    const struct nettle_hash *meta;    struct pike_string *digest;    unsigned length;       if (! THIS->ctx)    Pike_error("HashState not properly initialized.\n");       meta = GET_META(Pike_fp->current_object);    assert(meta);