/* hmac */ static void scrypt_hmac_init(scrypt_hmac_state *st, const uint8_t *key, size_t keylen) { uint8_t pad[SCRYPT_HASH_BLOCK_SIZE] = {0}; size_t i; scrypt_hash_init(&st->inner); scrypt_hash_init(&st->outer); if (keylen <= SCRYPT_HASH_BLOCK_SIZE) { /* use the key directly if it's <= blocksize bytes */ memcpy(pad, key, keylen); } else { /* if it's > blocksize bytes, hash it */ scrypt_hash(pad, key, keylen); } /* inner = (key ^ 0x36) */ /* h(inner || ...) */ for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) pad[i] ^= 0x36; scrypt_hash_update(&st->inner, pad, SCRYPT_HASH_BLOCK_SIZE); /* outer = (key ^ 0x5c) */ /* h(outer || ...) */ for (i = 0; i < SCRYPT_HASH_BLOCK_SIZE; i++) pad[i] ^= (0x5c ^ 0x36); scrypt_hash_update(&st->outer, pad, SCRYPT_HASH_BLOCK_SIZE); }
static PyObject *scrypt_getpowhash(PyObject *self, PyObject *args) { char *output; int timestamp; PyObject *value; PyStringObject *input; if (!PyArg_ParseTuple(args, "Si", &input, ×tamp)) return NULL; Py_INCREF(input); output = (char *)PyMem_Malloc(32); memset(output, 0, 32); scrypt_hash((char *)PyString_AsString((PyObject*) input), 80, (uint32_t *)output, GetNfactor(timestamp)); Py_DECREF(input); value = Py_BuildValue("s#", output, 32); PyMem_Free(output); return value; }