=item "p" (B<OSSL_KDF_PARAM_SCRYPT_P>) <unsigned integer>
-These parameters configure the scrypt work factors N, r and p.
-N is a parameter of type B<uint64_t>.
+=item "maxmem_bytes" (B<OSSL_KDF_PARAM_SCRYPT_MAXMEM>) <unsigned integer>
+
+These parameters configure the scrypt work factors N, r, maxmem and p.
+Both N and maxmem_bytes are parameters of type B<uint64_t>.
Both r and p are parameters of type B<uint32_t>.
+=item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
+
+This can be used to set the property query string when fetching the
+fixed digest internally. NULL is used if this value is not set.
+
=back
=head1 NOTES
OPENSSL_CTX *libctx, const char *propq);
typedef struct {
- void *provctx;
+ OPENSSL_CTX *libctx;
+ char *propq;
unsigned char *pass;
size_t pass_len;
unsigned char *salt;
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return NULL;
}
- ctx->provctx = provctx;
- ctx->sha256 = EVP_MD_fetch(PROV_LIBRARY_CONTEXT_OF(provctx),
- "sha256", NULL);
- if (ctx->sha256 == NULL) {
- OPENSSL_free(ctx);
- ERR_raise(ERR_LIB_PROV, PROV_R_UNABLE_TO_LOAD_SHA256);
- return NULL;
- }
+ ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
kdf_scrypt_init(ctx);
return ctx;
}
KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
if (ctx != NULL) {
+ OPENSSL_free(ctx->propq);
EVP_MD_free(ctx->sha256);
kdf_scrypt_reset(ctx);
OPENSSL_free(ctx);
return 1;
}
+static int set_digest(KDF_SCRYPT *ctx)
+{
+ EVP_MD_free(ctx->sha256);
+ ctx->sha256 = EVP_MD_fetch(ctx->libctx, "sha256", ctx->propq);
+ if (ctx->sha256 == NULL) {
+ OPENSSL_free(ctx);
+ ERR_raise(ERR_LIB_PROV, PROV_R_UNABLE_TO_LOAD_SHA256);
+ return 0;
+ }
+ return 1;
+}
+
+static int set_property_query(KDF_SCRYPT *ctx, const char *propq)
+{
+ OPENSSL_free(ctx->propq);
+ ctx->propq = NULL;
+ if (propq != NULL) {
+ ctx->propq = OPENSSL_strdup(propq);
+ if (ctx->propq == NULL) {
+ ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
+ return 0;
+ }
+ }
+ return 1;
+}
+
static int kdf_scrypt_derive(void *vctx, unsigned char *key,
size_t keylen)
{
return 0;
}
+ if (ctx->sha256 == NULL && !set_digest(ctx))
+ return 0;
+
return scrypt_alg((char *)ctx->pass, ctx->pass_len, ctx->salt,
ctx->salt_len, ctx->N, ctx->r, ctx->p,
ctx->maxmem_bytes, key, keylen, ctx->sha256,
- PROV_LIBRARY_CONTEXT_OF(ctx->provctx), NULL);
+ ctx->libctx, ctx->propq);
}
static int is_power_of_two(uint64_t value)
return 0;
ctx->maxmem_bytes = u64_value;
}
+
+ p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_PROPERTIES);
+ if (p != NULL) {
+ if (p->data_type != OSSL_PARAM_UTF8_STRING
+ || !set_property_query(ctx, p->data)
+ || !set_digest(ctx))
+ return 0;
+ }
return 1;
}
OSSL_PARAM_uint32(OSSL_KDF_PARAM_SCRYPT_R, NULL),
OSSL_PARAM_uint32(OSSL_KDF_PARAM_SCRYPT_P, NULL),
OSSL_PARAM_uint64(OSSL_KDF_PARAM_SCRYPT_MAXMEM, NULL),
+ OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_PROPERTIES, NULL, 0),
OSSL_PARAM_END
};
return known_settable_ctx_params;