sync with OpenBSD -current
This commit is contained in:
parent
6dadaa4a5d
commit
43f516ce43
14 changed files with 589 additions and 700 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: t_x509.c,v 1.46 2024/08/28 06:17:06 tb Exp $ */
|
/* $OpenBSD: t_x509.c,v 1.47 2025/01/11 03:00:04 tb Exp $ */
|
||||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -508,10 +508,10 @@ X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)
|
||||||
|
|
||||||
c = s;
|
c = s;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (((*s == '/') &&
|
if ((s[0] == '/' &&
|
||||||
((s[1] >= 'A') && (s[1] <= 'Z') &&
|
(s[1] >= 'A' && s[1] <= 'Z' &&
|
||||||
((s[2] == '=') || ((s[2] >= 'A') && (s[2] <= 'Z') &&
|
(s[2] == '=' || (s[2] >= 'A' && s[2] <= 'Z' &&
|
||||||
(s[3] == '='))))) || (*s == '\0')) {
|
s[3] == '=')))) || s[0] == '\0') {
|
||||||
i = s - c;
|
i = s - c;
|
||||||
if (BIO_write(bp, c, i) != i)
|
if (BIO_write(bp, c, i) != i)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ec_key.c,v 1.48 2024/11/16 10:38:10 tb Exp $ */
|
/* $OpenBSD: ec_key.c,v 1.50 2025/01/11 20:57:03 tb Exp $ */
|
||||||
/*
|
/*
|
||||||
* Written by Nils Larsch for the OpenSSL project.
|
* Written by Nils Larsch for the OpenSSL project.
|
||||||
*/
|
*/
|
||||||
|
@ -235,7 +235,7 @@ EC_KEY_generate_key(EC_KEY *eckey)
|
||||||
}
|
}
|
||||||
LCRYPTO_ALIAS(EC_KEY_generate_key);
|
LCRYPTO_ALIAS(EC_KEY_generate_key);
|
||||||
|
|
||||||
int
|
static int
|
||||||
ec_key_gen(EC_KEY *eckey)
|
ec_key_gen(EC_KEY *eckey)
|
||||||
{
|
{
|
||||||
BIGNUM *priv_key = NULL;
|
BIGNUM *priv_key = NULL;
|
||||||
|
@ -592,6 +592,8 @@ EC_KEY_new_method(ENGINE *engine)
|
||||||
}
|
}
|
||||||
LCRYPTO_ALIAS(EC_KEY_new_method);
|
LCRYPTO_ALIAS(EC_KEY_new_method);
|
||||||
|
|
||||||
|
#define EC_KEY_METHOD_DYNAMIC 1
|
||||||
|
|
||||||
EC_KEY_METHOD *
|
EC_KEY_METHOD *
|
||||||
EC_KEY_METHOD_new(const EC_KEY_METHOD *meth)
|
EC_KEY_METHOD_new(const EC_KEY_METHOD *meth)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ec_lib.c,v 1.105 2025/01/09 11:35:46 tb Exp $ */
|
/* $OpenBSD: ec_lib.c,v 1.111 2025/01/11 15:26:07 tb Exp $ */
|
||||||
/*
|
/*
|
||||||
* Originally written by Bodo Moeller for the OpenSSL project.
|
* Originally written by Bodo Moeller for the OpenSSL project.
|
||||||
*/
|
*/
|
||||||
|
@ -1026,8 +1026,9 @@ LCRYPTO_ALIAS(EC_POINT_get_affine_coordinates_GFp);
|
||||||
|
|
||||||
int
|
int
|
||||||
EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
|
EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||||
const BIGNUM *x, int y_bit, BN_CTX *ctx_in)
|
const BIGNUM *in_x, int y_bit, BN_CTX *ctx_in)
|
||||||
{
|
{
|
||||||
|
BIGNUM *p, *a, *b, *w, *x, *y;
|
||||||
BN_CTX *ctx;
|
BN_CTX *ctx;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
@ -1036,18 +1037,90 @@ EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (group->meth->point_set_compressed_coordinates == NULL) {
|
y_bit = (y_bit != 0);
|
||||||
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
|
||||||
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
|
if ((p = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((a = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((b = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((w = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((x = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((y = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Weierstrass equation: y^2 = x^3 + ax + b, so y is one of the
|
||||||
|
* square roots of x^3 + ax + b. The y-bit indicates which one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!EC_GROUP_get_curve(group, p, a, b, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* XXX - should we not insist on 0 <= x < p instead? */
|
||||||
|
if (!BN_nnmod(x, in_x, p, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* y = x^3 */
|
||||||
|
if (!BN_mod_sqr(y, x, p, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_mul(y, y, x, p, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* y += ax */
|
||||||
|
if (group->a_is_minus3) {
|
||||||
|
if (!BN_mod_lshift1_quick(w, x, p))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_add_quick(w, w, x, p))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_sub_quick(y, y, w, p))
|
||||||
|
goto err;
|
||||||
|
} else {
|
||||||
|
if (!BN_mod_mul(w, a, x, p, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_add_quick(y, y, w, p))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* y += b */
|
||||||
|
if (!BN_mod_add_quick(y, y, b, p))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!BN_mod_sqrt(y, y, p, ctx)) {
|
||||||
|
ECerror(EC_R_INVALID_COMPRESSED_POINT);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (group->meth != point->meth) {
|
|
||||||
ECerror(EC_R_INCOMPATIBLE_OBJECTS);
|
if (y_bit == BN_is_odd(y))
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
if (BN_is_zero(y)) {
|
||||||
|
ECerror(EC_R_INVALID_COMPRESSION_BIT);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
ret = group->meth->point_set_compressed_coordinates(group, point,
|
if (!BN_usub(y, p, y))
|
||||||
x, y_bit, ctx);
|
goto err;
|
||||||
|
|
||||||
|
if (y_bit != BN_is_odd(y)) {
|
||||||
|
/* Can only happen if p is even and should not be reachable. */
|
||||||
|
ECerror(ERR_R_INTERNAL_ERROR);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
BN_CTX_end(ctx);
|
||||||
|
|
||||||
if (ctx != ctx_in)
|
if (ctx != ctx_in)
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
|
|
||||||
|
@ -1177,7 +1250,7 @@ EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (group->meth->is_on_curve == NULL) {
|
if (group->meth->point_is_on_curve == NULL) {
|
||||||
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -1185,7 +1258,7 @@ EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
|
||||||
ECerror(EC_R_INCOMPATIBLE_OBJECTS);
|
ECerror(EC_R_INCOMPATIBLE_OBJECTS);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
ret = group->meth->is_on_curve(group, point, ctx);
|
ret = group->meth->point_is_on_curve(group, point, ctx);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (ctx != ctx_in)
|
if (ctx != ctx_in)
|
||||||
|
@ -1229,6 +1302,7 @@ int
|
||||||
EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in)
|
EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in)
|
||||||
{
|
{
|
||||||
BN_CTX *ctx;
|
BN_CTX *ctx;
|
||||||
|
BIGNUM *x, *y;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if ((ctx = ctx_in) == NULL)
|
if ((ctx = ctx_in) == NULL)
|
||||||
|
@ -1236,17 +1310,23 @@ EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in)
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (group->meth->make_affine == NULL) {
|
BN_CTX_start(ctx);
|
||||||
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
|
||||||
|
if ((x = BN_CTX_get(ctx)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
if ((y = BN_CTX_get(ctx)) == NULL)
|
||||||
if (group->meth != point->meth) {
|
|
||||||
ECerror(EC_R_INCOMPATIBLE_OBJECTS);
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
ret = group->meth->make_affine(group, point, ctx);
|
if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
BN_CTX_end(ctx);
|
||||||
|
|
||||||
if (ctx != ctx_in)
|
if (ctx != ctx_in)
|
||||||
BN_CTX_free(ctx);
|
BN_CTX_free(ctx);
|
||||||
|
|
||||||
|
@ -1254,81 +1334,6 @@ EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx_in)
|
||||||
}
|
}
|
||||||
LCRYPTO_ALIAS(EC_POINT_make_affine);
|
LCRYPTO_ALIAS(EC_POINT_make_affine);
|
||||||
|
|
||||||
int
|
|
||||||
EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
|
|
||||||
BN_CTX *ctx_in)
|
|
||||||
{
|
|
||||||
BN_CTX *ctx;
|
|
||||||
size_t i;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if ((ctx = ctx_in) == NULL)
|
|
||||||
ctx = BN_CTX_new();
|
|
||||||
if (ctx == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (group->meth->points_make_affine == NULL) {
|
|
||||||
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
if (group->meth != points[i]->meth) {
|
|
||||||
ECerror(EC_R_INCOMPATIBLE_OBJECTS);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = group->meth->points_make_affine(group, num, points, ctx);
|
|
||||||
|
|
||||||
err:
|
|
||||||
if (ctx != ctx_in)
|
|
||||||
BN_CTX_free(ctx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
LCRYPTO_ALIAS(EC_POINTs_make_affine);
|
|
||||||
|
|
||||||
int
|
|
||||||
EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
|
|
||||||
size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
|
|
||||||
BN_CTX *ctx_in)
|
|
||||||
{
|
|
||||||
BN_CTX *ctx;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if ((ctx = ctx_in) == NULL)
|
|
||||||
ctx = BN_CTX_new();
|
|
||||||
if (ctx == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Only num == 0 and num == 1 is supported. */
|
|
||||||
if (group->meth->mul_generator_ct == NULL ||
|
|
||||||
group->meth->mul_single_ct == NULL ||
|
|
||||||
group->meth->mul_double_nonct == NULL ||
|
|
||||||
num > 1) {
|
|
||||||
ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num == 1 && points != NULL && scalars != NULL) {
|
|
||||||
/* Either bP or aG + bP, this is sane. */
|
|
||||||
ret = EC_POINT_mul(group, r, scalar, points[0], scalars[0], ctx);
|
|
||||||
} else if (scalar != NULL && points == NULL && scalars == NULL) {
|
|
||||||
/* aG, this is sane */
|
|
||||||
ret = EC_POINT_mul(group, r, scalar, NULL, NULL, ctx);
|
|
||||||
} else {
|
|
||||||
/* anything else is an error */
|
|
||||||
ECerror(ERR_R_EC_LIB);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err:
|
|
||||||
if (ctx != ctx_in)
|
|
||||||
BN_CTX_free(ctx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
LCRYPTO_ALIAS(EC_POINTs_mul);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
|
EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
|
||||||
const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx_in)
|
const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx_in)
|
||||||
|
@ -1426,3 +1431,22 @@ EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LCRYPTO_ALIAS(EC_POINT_get_Jprojective_coordinates_GFp);
|
LCRYPTO_ALIAS(EC_POINT_get_Jprojective_coordinates_GFp);
|
||||||
|
|
||||||
|
int
|
||||||
|
EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
|
||||||
|
BN_CTX *ctx_in)
|
||||||
|
{
|
||||||
|
ECerror(ERR_R_DISABLED);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LCRYPTO_ALIAS(EC_POINTs_make_affine);
|
||||||
|
|
||||||
|
int
|
||||||
|
EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
|
||||||
|
size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
|
||||||
|
BN_CTX *ctx_in)
|
||||||
|
{
|
||||||
|
ECerror(ERR_R_DISABLED);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LCRYPTO_ALIAS(EC_POINTs_mul);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ec_local.h,v 1.54 2025/01/07 08:52:17 tb Exp $ */
|
/* $OpenBSD: ec_local.h,v 1.62 2025/01/11 20:57:03 tb Exp $ */
|
||||||
/*
|
/*
|
||||||
* Originally written by Bodo Moeller for the OpenSSL project.
|
* Originally written by Bodo Moeller for the OpenSSL project.
|
||||||
*/
|
*/
|
||||||
|
@ -79,12 +79,6 @@
|
||||||
|
|
||||||
__BEGIN_HIDDEN_DECLS
|
__BEGIN_HIDDEN_DECLS
|
||||||
|
|
||||||
#if defined(__SUNPRO_C)
|
|
||||||
# if __SUNPRO_C >= 0x520
|
|
||||||
# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ec_method_st {
|
struct ec_method_st {
|
||||||
int field_type;
|
int field_type;
|
||||||
|
|
||||||
|
@ -93,26 +87,24 @@ struct ec_method_st {
|
||||||
int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
|
int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
|
||||||
BIGNUM *b, BN_CTX *);
|
BIGNUM *b, BN_CTX *);
|
||||||
|
|
||||||
|
int (*point_is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
|
||||||
|
int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
|
||||||
|
BN_CTX *);
|
||||||
|
|
||||||
int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *,
|
int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *,
|
||||||
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
|
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
|
||||||
int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *,
|
int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *,
|
||||||
BIGNUM *x, BIGNUM *y, BN_CTX *);
|
BIGNUM *x, BIGNUM *y, BN_CTX *);
|
||||||
int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *,
|
|
||||||
const BIGNUM *x, int y_bit, BN_CTX *);
|
/* Only used by the wNAF code. */
|
||||||
|
int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT **,
|
||||||
|
BN_CTX *);
|
||||||
|
|
||||||
int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
|
int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
|
||||||
const EC_POINT *b, BN_CTX *);
|
const EC_POINT *b, BN_CTX *);
|
||||||
int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
|
int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
|
||||||
int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
|
int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
|
||||||
|
|
||||||
int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
|
|
||||||
int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
|
|
||||||
BN_CTX *);
|
|
||||||
|
|
||||||
int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
|
|
||||||
int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[],
|
|
||||||
BN_CTX *);
|
|
||||||
|
|
||||||
int (*mul_generator_ct)(const EC_GROUP *, EC_POINT *r,
|
int (*mul_generator_ct)(const EC_GROUP *, EC_POINT *r,
|
||||||
const BIGNUM *scalar, BN_CTX *);
|
const BIGNUM *scalar, BN_CTX *);
|
||||||
int (*mul_single_ct)(const EC_GROUP *group, EC_POINT *r,
|
int (*mul_single_ct)(const EC_GROUP *group, EC_POINT *r,
|
||||||
|
@ -139,10 +131,6 @@ struct ec_method_st {
|
||||||
} /* EC_METHOD */;
|
} /* EC_METHOD */;
|
||||||
|
|
||||||
struct ec_group_st {
|
struct ec_group_st {
|
||||||
/*
|
|
||||||
* Methods and members exposed via the public API.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const EC_METHOD *meth;
|
const EC_METHOD *meth;
|
||||||
|
|
||||||
EC_POINT *generator; /* Optional */
|
EC_POINT *generator; /* Optional */
|
||||||
|
@ -231,8 +219,6 @@ struct ec_key_method_st {
|
||||||
const ECDSA_SIG *sig, EC_KEY *eckey);
|
const ECDSA_SIG *sig, EC_KEY *eckey);
|
||||||
} /* EC_KEY_METHOD */;
|
} /* EC_KEY_METHOD */;
|
||||||
|
|
||||||
#define EC_KEY_METHOD_DYNAMIC 1
|
|
||||||
|
|
||||||
struct ec_key_st {
|
struct ec_key_st {
|
||||||
const EC_KEY_METHOD *meth;
|
const EC_KEY_METHOD *meth;
|
||||||
|
|
||||||
|
@ -253,7 +239,6 @@ struct ec_key_st {
|
||||||
} /* EC_KEY */;
|
} /* EC_KEY */;
|
||||||
|
|
||||||
int eckey_compute_pubkey(EC_KEY *eckey);
|
int eckey_compute_pubkey(EC_KEY *eckey);
|
||||||
int ec_key_gen(EC_KEY *eckey);
|
|
||||||
int ecdh_compute_key(unsigned char **out, size_t *out_len,
|
int ecdh_compute_key(unsigned char **out, size_t *out_len,
|
||||||
const EC_POINT *pub_key, const EC_KEY *ecdh);
|
const EC_POINT *pub_key, const EC_KEY *ecdh);
|
||||||
int ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
|
int ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ec_mult.c,v 1.56 2024/12/19 21:05:46 tb Exp $ */
|
/* $OpenBSD: ec_mult.c,v 1.57 2025/01/11 13:58:31 tb Exp $ */
|
||||||
/*
|
/*
|
||||||
* Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
|
* Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
|
||||||
*/
|
*/
|
||||||
|
@ -219,7 +219,7 @@ ec_normalize_points(const EC_GROUP *group, struct ec_wnaf *wnaf0,
|
||||||
memcpy(&val[0], points0, sizeof(*val) * len0);
|
memcpy(&val[0], points0, sizeof(*val) * len0);
|
||||||
memcpy(&val[len0], points1, sizeof(*val) * len1);
|
memcpy(&val[len0], points1, sizeof(*val) * len1);
|
||||||
|
|
||||||
if (!EC_POINTs_make_affine(group, len, val, ctx))
|
if (!group->meth->points_make_affine(group, len, val, ctx))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ecp_methods.c,v 1.26 2025/01/07 08:30:52 tb Exp $ */
|
/* $OpenBSD: ecp_methods.c,v 1.36 2025/01/11 21:20:39 tb Exp $ */
|
||||||
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
|
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
|
||||||
* for the OpenSSL project.
|
* for the OpenSSL project.
|
||||||
* Includes code written by Bodo Moeller for the OpenSSL project.
|
* Includes code written by Bodo Moeller for the OpenSSL project.
|
||||||
|
@ -166,6 +166,195 @@ ec_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ec_point_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
|
||||||
|
{
|
||||||
|
int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
|
||||||
|
int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
|
||||||
|
const BIGNUM *p;
|
||||||
|
BIGNUM *rh, *tmp, *Z4, *Z6;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (EC_POINT_is_at_infinity(group, point))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
field_mul = group->meth->field_mul;
|
||||||
|
field_sqr = group->meth->field_sqr;
|
||||||
|
p = group->p;
|
||||||
|
|
||||||
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
|
if ((rh = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((tmp = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((Z4 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
if ((Z6 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The curve is defined by a Weierstrass equation y^2 = x^3 + a*x + b.
|
||||||
|
* The point is given in Jacobian projective coordinates where (X, Y, Z)
|
||||||
|
* represents (x, y) = (X/Z^2, Y/Z^3). Substituting this and multiplying
|
||||||
|
* by Z^6 transforms the above into Y^2 = X^3 + a*X*Z^4 + b*Z^6.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* rh := X^2 */
|
||||||
|
if (!field_sqr(group, rh, point->X, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!point->Z_is_one) {
|
||||||
|
if (!field_sqr(group, tmp, point->Z, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!field_sqr(group, Z4, tmp, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!field_mul(group, Z6, Z4, tmp, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* rh := (rh + a*Z^4)*X */
|
||||||
|
if (group->a_is_minus3) {
|
||||||
|
if (!BN_mod_lshift1_quick(tmp, Z4, p))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_add_quick(tmp, tmp, Z4, p))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_sub_quick(rh, rh, tmp, p))
|
||||||
|
goto err;
|
||||||
|
if (!field_mul(group, rh, rh, point->X, ctx))
|
||||||
|
goto err;
|
||||||
|
} else {
|
||||||
|
if (!field_mul(group, tmp, Z4, group->a, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_add_quick(rh, rh, tmp, p))
|
||||||
|
goto err;
|
||||||
|
if (!field_mul(group, rh, rh, point->X, ctx))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* rh := rh + b*Z^6 */
|
||||||
|
if (!field_mul(group, tmp, group->b, Z6, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!BN_mod_add_quick(rh, rh, tmp, p))
|
||||||
|
goto err;
|
||||||
|
} else {
|
||||||
|
/* point->Z_is_one */
|
||||||
|
|
||||||
|
/* rh := (rh + a)*X */
|
||||||
|
if (!BN_mod_add_quick(rh, rh, group->a, p))
|
||||||
|
goto err;
|
||||||
|
if (!field_mul(group, rh, rh, point->X, ctx))
|
||||||
|
goto err;
|
||||||
|
/* rh := rh + b */
|
||||||
|
if (!BN_mod_add_quick(rh, rh, group->b, p))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 'lh' := Y^2 */
|
||||||
|
if (!field_sqr(group, tmp, point->Y, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ret = (0 == BN_ucmp(tmp, rh));
|
||||||
|
|
||||||
|
err:
|
||||||
|
BN_CTX_end(ctx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns -1 on error, 0 if the points are equal, 1 if the points are distinct.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
ec_point_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
|
||||||
|
BN_CTX *ctx)
|
||||||
|
{
|
||||||
|
int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
|
||||||
|
int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
|
||||||
|
BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
|
||||||
|
const BIGNUM *tmp1_, *tmp2_;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (EC_POINT_is_at_infinity(group, a) && EC_POINT_is_at_infinity(group, b))
|
||||||
|
return 0;
|
||||||
|
if (EC_POINT_is_at_infinity(group, a) || EC_POINT_is_at_infinity(group, b))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (a->Z_is_one && b->Z_is_one)
|
||||||
|
return BN_cmp(a->X, b->X) != 0 || BN_cmp(a->Y, b->Y) != 0;
|
||||||
|
|
||||||
|
field_mul = group->meth->field_mul;
|
||||||
|
field_sqr = group->meth->field_sqr;
|
||||||
|
|
||||||
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
|
if ((tmp1 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto end;
|
||||||
|
if ((tmp2 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto end;
|
||||||
|
if ((Za23 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto end;
|
||||||
|
if ((Zb23 = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Decide whether (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3), or
|
||||||
|
* equivalently, (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!b->Z_is_one) {
|
||||||
|
if (!field_sqr(group, Zb23, b->Z, ctx))
|
||||||
|
goto end;
|
||||||
|
if (!field_mul(group, tmp1, a->X, Zb23, ctx))
|
||||||
|
goto end;
|
||||||
|
tmp1_ = tmp1;
|
||||||
|
} else
|
||||||
|
tmp1_ = a->X;
|
||||||
|
if (!a->Z_is_one) {
|
||||||
|
if (!field_sqr(group, Za23, a->Z, ctx))
|
||||||
|
goto end;
|
||||||
|
if (!field_mul(group, tmp2, b->X, Za23, ctx))
|
||||||
|
goto end;
|
||||||
|
tmp2_ = tmp2;
|
||||||
|
} else
|
||||||
|
tmp2_ = b->X;
|
||||||
|
|
||||||
|
/* compare X_a*Z_b^2 with X_b*Z_a^2 */
|
||||||
|
if (BN_cmp(tmp1_, tmp2_) != 0) {
|
||||||
|
ret = 1; /* points differ */
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (!b->Z_is_one) {
|
||||||
|
if (!field_mul(group, Zb23, Zb23, b->Z, ctx))
|
||||||
|
goto end;
|
||||||
|
if (!field_mul(group, tmp1, a->Y, Zb23, ctx))
|
||||||
|
goto end;
|
||||||
|
/* tmp1_ = tmp1 */
|
||||||
|
} else
|
||||||
|
tmp1_ = a->Y;
|
||||||
|
if (!a->Z_is_one) {
|
||||||
|
if (!field_mul(group, Za23, Za23, a->Z, ctx))
|
||||||
|
goto end;
|
||||||
|
if (!field_mul(group, tmp2, b->Y, Za23, ctx))
|
||||||
|
goto end;
|
||||||
|
/* tmp2_ = tmp2 */
|
||||||
|
} else
|
||||||
|
tmp2_ = b->Y;
|
||||||
|
|
||||||
|
/* compare Y_a*Z_b^3 with Y_b*Z_a^3 */
|
||||||
|
if (BN_cmp(tmp1_, tmp2_) != 0) {
|
||||||
|
ret = 1; /* points differ */
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
/* points are equal */
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
end:
|
||||||
|
BN_CTX_end(ctx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ec_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
|
ec_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||||
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
|
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
|
||||||
|
@ -276,99 +465,135 @@ ec_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ec_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
|
ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT **points,
|
||||||
const BIGNUM *in_x, int y_bit, BN_CTX *ctx)
|
BN_CTX *ctx)
|
||||||
{
|
{
|
||||||
const BIGNUM *p = group->p, *a = group->a, *b = group->b;
|
BIGNUM **prod_Z = NULL;
|
||||||
BIGNUM *w, *x, *y;
|
BIGNUM *one, *tmp, *tmp_Z;
|
||||||
|
size_t i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
y_bit = (y_bit != 0);
|
if (num == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
if ((w = BN_CTX_get(ctx)) == NULL)
|
if ((one = BN_CTX_get(ctx)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
if ((x = BN_CTX_get(ctx)) == NULL)
|
if ((tmp = BN_CTX_get(ctx)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
if ((y = BN_CTX_get(ctx)) == NULL)
|
if ((tmp_Z = BN_CTX_get(ctx)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
if (!ec_encode_scalar(group, one, BN_value_one(), ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if ((prod_Z = calloc(num, sizeof *prod_Z)) == NULL)
|
||||||
|
goto err;
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
if ((prod_Z[i] = BN_CTX_get(ctx)) == NULL)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Weierstrass equation: y^2 = x^3 + ax + b, so y is one of the
|
* Set prod_Z[i] to the product of points[0]->Z, ..., points[i]->Z,
|
||||||
* square roots of x^3 + ax + b. The y-bit indicates which one.
|
* skipping any zero-valued inputs (pretend that they're 1).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* XXX - should we not insist on 0 <= x < p instead? */
|
if (!BN_is_zero(points[0]->Z)) {
|
||||||
if (!BN_nnmod(x, in_x, p, ctx))
|
if (!bn_copy(prod_Z[0], points[0]->Z))
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (group->meth->field_encode != NULL) {
|
|
||||||
if (!group->meth->field_encode(group, x, x, ctx))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* y = x^3 */
|
|
||||||
if (!group->meth->field_sqr(group, y, x, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!group->meth->field_mul(group, y, y, x, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* y += ax */
|
|
||||||
if (group->a_is_minus3) {
|
|
||||||
if (!BN_mod_lshift1_quick(w, x, p))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_add_quick(w, w, x, p))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_sub_quick(y, y, w, p))
|
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
if (!group->meth->field_mul(group, w, a, x, ctx))
|
if (!bn_copy(prod_Z[0], one))
|
||||||
goto err;
|
|
||||||
if (!BN_mod_add_quick(y, y, w, p))
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* y += b */
|
for (i = 1; i < num; i++) {
|
||||||
if (!BN_mod_add_quick(y, y, b, p))
|
if (!BN_is_zero(points[i]->Z)) {
|
||||||
goto err;
|
if (!group->meth->field_mul(group, prod_Z[i],
|
||||||
|
prod_Z[i - 1], points[i]->Z, ctx))
|
||||||
|
goto err;
|
||||||
|
} else {
|
||||||
|
if (!bn_copy(prod_Z[i], prod_Z[i - 1]))
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (group->meth->field_decode != NULL) {
|
/*
|
||||||
if (!group->meth->field_decode(group, x, x, ctx))
|
* Now use a single explicit inversion to replace every non-zero
|
||||||
|
* points[i]->Z by its inverse.
|
||||||
|
*/
|
||||||
|
if (!BN_mod_inverse_nonct(tmp, prod_Z[num - 1], group->p, ctx)) {
|
||||||
|
ECerror(ERR_R_BN_LIB);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group->meth->field_encode != NULL) {
|
||||||
|
/*
|
||||||
|
* In the Montgomery case we just turned R*H (representing H)
|
||||||
|
* into 1/(R*H), but we need R*(1/H) (representing 1/H); i.e.,
|
||||||
|
* we need to multiply by the Montgomery factor twice.
|
||||||
|
*/
|
||||||
|
if (!group->meth->field_encode(group, tmp, tmp, ctx))
|
||||||
goto err;
|
goto err;
|
||||||
if (!group->meth->field_decode(group, y, y, ctx))
|
if (!group->meth->field_encode(group, tmp, tmp, ctx))
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!BN_mod_sqrt(y, y, p, ctx)) {
|
for (i = num - 1; i > 0; i--) {
|
||||||
ECerror(EC_R_INVALID_COMPRESSED_POINT);
|
/*
|
||||||
goto err;
|
* Loop invariant: tmp is the product of the inverses of
|
||||||
|
* points[0]->Z, ..., points[i]->Z (zero-valued inputs skipped).
|
||||||
|
*/
|
||||||
|
if (BN_is_zero(points[i]->Z))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Set tmp_Z to the inverse of points[i]->Z. */
|
||||||
|
if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))
|
||||||
|
goto err;
|
||||||
|
/* Adjust tmp to satisfy loop invariant. */
|
||||||
|
if (!group->meth->field_mul(group, tmp, tmp, points[i]->Z, ctx))
|
||||||
|
goto err;
|
||||||
|
/* Replace points[i]->Z by its inverse. */
|
||||||
|
if (!bn_copy(points[i]->Z, tmp_Z))
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y_bit == BN_is_odd(y))
|
if (!BN_is_zero(points[0]->Z)) {
|
||||||
goto done;
|
/* Replace points[0]->Z by its inverse. */
|
||||||
|
if (!bn_copy(points[0]->Z, tmp))
|
||||||
if (BN_is_zero(y)) {
|
goto err;
|
||||||
ECerror(EC_R_INVALID_COMPRESSION_BIT);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
if (!BN_usub(y, p, y))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (y_bit != BN_is_odd(y)) {
|
|
||||||
/* Can only happen if p is even and should not be reachable. */
|
|
||||||
ECerror(ERR_R_INTERNAL_ERROR);
|
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
/* Finally, fix up the X and Y coordinates for all points. */
|
||||||
if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
|
for (i = 0; i < num; i++) {
|
||||||
goto err;
|
EC_POINT *p = points[i];
|
||||||
|
|
||||||
|
if (BN_is_zero(p->Z))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
|
||||||
|
|
||||||
|
if (!group->meth->field_sqr(group, tmp, p->Z, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!group->meth->field_mul(group, p->X, p->X, tmp, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!group->meth->field_mul(group, tmp, tmp, p->Z, ctx))
|
||||||
|
goto err;
|
||||||
|
if (!group->meth->field_mul(group, p->Y, p->Y, tmp, ctx))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (!bn_copy(p->Z, one))
|
||||||
|
goto err;
|
||||||
|
p->Z_is_one = 1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
|
free(prod_Z);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -700,363 +925,6 @@ ec_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
|
||||||
return BN_usub(point->Y, group->p, point->Y);
|
return BN_usub(point->Y, group->p, point->Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
ec_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
|
|
||||||
{
|
|
||||||
int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
|
|
||||||
int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
|
|
||||||
const BIGNUM *p;
|
|
||||||
BIGNUM *rh, *tmp, *Z4, *Z6;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (EC_POINT_is_at_infinity(group, point))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
field_mul = group->meth->field_mul;
|
|
||||||
field_sqr = group->meth->field_sqr;
|
|
||||||
p = group->p;
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
|
||||||
|
|
||||||
if ((rh = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((tmp = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((Z4 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((Z6 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We have a curve defined by a Weierstrass equation y^2 = x^3 + a*x
|
|
||||||
* + b. The point to consider is given in Jacobian projective
|
|
||||||
* coordinates where (X, Y, Z) represents (x, y) = (X/Z^2, Y/Z^3).
|
|
||||||
* Substituting this and multiplying by Z^6 transforms the above
|
|
||||||
* equation into Y^2 = X^3 + a*X*Z^4 + b*Z^6. To test this, we add up
|
|
||||||
* the right-hand side in 'rh'.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* rh := X^2 */
|
|
||||||
if (!field_sqr(group, rh, point->X, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!point->Z_is_one) {
|
|
||||||
if (!field_sqr(group, tmp, point->Z, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!field_sqr(group, Z4, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!field_mul(group, Z6, Z4, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* rh := (rh + a*Z^4)*X */
|
|
||||||
if (group->a_is_minus3) {
|
|
||||||
if (!BN_mod_lshift1_quick(tmp, Z4, p))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_add_quick(tmp, tmp, Z4, p))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_sub_quick(rh, rh, tmp, p))
|
|
||||||
goto err;
|
|
||||||
if (!field_mul(group, rh, rh, point->X, ctx))
|
|
||||||
goto err;
|
|
||||||
} else {
|
|
||||||
if (!field_mul(group, tmp, Z4, group->a, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_add_quick(rh, rh, tmp, p))
|
|
||||||
goto err;
|
|
||||||
if (!field_mul(group, rh, rh, point->X, ctx))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rh := rh + b*Z^6 */
|
|
||||||
if (!field_mul(group, tmp, group->b, Z6, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!BN_mod_add_quick(rh, rh, tmp, p))
|
|
||||||
goto err;
|
|
||||||
} else {
|
|
||||||
/* point->Z_is_one */
|
|
||||||
|
|
||||||
/* rh := (rh + a)*X */
|
|
||||||
if (!BN_mod_add_quick(rh, rh, group->a, p))
|
|
||||||
goto err;
|
|
||||||
if (!field_mul(group, rh, rh, point->X, ctx))
|
|
||||||
goto err;
|
|
||||||
/* rh := rh + b */
|
|
||||||
if (!BN_mod_add_quick(rh, rh, group->b, p))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 'lh' := Y^2 */
|
|
||||||
if (!field_sqr(group, tmp, point->Y, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
ret = (0 == BN_ucmp(tmp, rh));
|
|
||||||
|
|
||||||
err:
|
|
||||||
BN_CTX_end(ctx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns -1 on error, 0 if the points are equal, 1 if the points are distinct.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int
|
|
||||||
ec_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
|
|
||||||
{
|
|
||||||
int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
|
|
||||||
int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
|
|
||||||
BIGNUM *tmp1, *tmp2, *Za23, *Zb23;
|
|
||||||
const BIGNUM *tmp1_, *tmp2_;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (EC_POINT_is_at_infinity(group, a) && EC_POINT_is_at_infinity(group, b))
|
|
||||||
return 0;
|
|
||||||
if (EC_POINT_is_at_infinity(group, a) || EC_POINT_is_at_infinity(group, b))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (a->Z_is_one && b->Z_is_one)
|
|
||||||
return BN_cmp(a->X, b->X) != 0 || BN_cmp(a->Y, b->Y) != 0;
|
|
||||||
|
|
||||||
field_mul = group->meth->field_mul;
|
|
||||||
field_sqr = group->meth->field_sqr;
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
|
||||||
|
|
||||||
if ((tmp1 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto end;
|
|
||||||
if ((tmp2 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto end;
|
|
||||||
if ((Za23 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto end;
|
|
||||||
if ((Zb23 = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We have to decide whether (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2,
|
|
||||||
* Y_b/Z_b^3), or equivalently, whether (X_a*Z_b^2, Y_a*Z_b^3) =
|
|
||||||
* (X_b*Z_a^2, Y_b*Z_a^3).
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!b->Z_is_one) {
|
|
||||||
if (!field_sqr(group, Zb23, b->Z, ctx))
|
|
||||||
goto end;
|
|
||||||
if (!field_mul(group, tmp1, a->X, Zb23, ctx))
|
|
||||||
goto end;
|
|
||||||
tmp1_ = tmp1;
|
|
||||||
} else
|
|
||||||
tmp1_ = a->X;
|
|
||||||
if (!a->Z_is_one) {
|
|
||||||
if (!field_sqr(group, Za23, a->Z, ctx))
|
|
||||||
goto end;
|
|
||||||
if (!field_mul(group, tmp2, b->X, Za23, ctx))
|
|
||||||
goto end;
|
|
||||||
tmp2_ = tmp2;
|
|
||||||
} else
|
|
||||||
tmp2_ = b->X;
|
|
||||||
|
|
||||||
/* compare X_a*Z_b^2 with X_b*Z_a^2 */
|
|
||||||
if (BN_cmp(tmp1_, tmp2_) != 0) {
|
|
||||||
ret = 1; /* points differ */
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
if (!b->Z_is_one) {
|
|
||||||
if (!field_mul(group, Zb23, Zb23, b->Z, ctx))
|
|
||||||
goto end;
|
|
||||||
if (!field_mul(group, tmp1, a->Y, Zb23, ctx))
|
|
||||||
goto end;
|
|
||||||
/* tmp1_ = tmp1 */
|
|
||||||
} else
|
|
||||||
tmp1_ = a->Y;
|
|
||||||
if (!a->Z_is_one) {
|
|
||||||
if (!field_mul(group, Za23, Za23, a->Z, ctx))
|
|
||||||
goto end;
|
|
||||||
if (!field_mul(group, tmp2, b->Y, Za23, ctx))
|
|
||||||
goto end;
|
|
||||||
/* tmp2_ = tmp2 */
|
|
||||||
} else
|
|
||||||
tmp2_ = b->Y;
|
|
||||||
|
|
||||||
/* compare Y_a*Z_b^3 with Y_b*Z_a^3 */
|
|
||||||
if (BN_cmp(tmp1_, tmp2_) != 0) {
|
|
||||||
ret = 1; /* points differ */
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
/* points are equal */
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
end:
|
|
||||||
BN_CTX_end(ctx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
ec_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
|
|
||||||
{
|
|
||||||
BIGNUM *x, *y;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
|
||||||
|
|
||||||
if ((x = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((y = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!point->Z_is_one) {
|
|
||||||
ECerror(ERR_R_INTERNAL_ERROR);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
ret = 1;
|
|
||||||
|
|
||||||
err:
|
|
||||||
BN_CTX_end(ctx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
ec_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
|
|
||||||
BN_CTX *ctx)
|
|
||||||
{
|
|
||||||
BIGNUM **prod_Z = NULL;
|
|
||||||
BIGNUM *one, *tmp, *tmp_Z;
|
|
||||||
size_t i;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (num == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
|
||||||
|
|
||||||
if ((one = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((tmp = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
if ((tmp_Z = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!ec_encode_scalar(group, one, BN_value_one(), ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if ((prod_Z = calloc(num, sizeof *prod_Z)) == NULL)
|
|
||||||
goto err;
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
if ((prod_Z[i] = BN_CTX_get(ctx)) == NULL)
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set prod_Z[i] to the product of points[0]->Z, ..., points[i]->Z,
|
|
||||||
* skipping any zero-valued inputs (pretend that they're 1).
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!BN_is_zero(points[0]->Z)) {
|
|
||||||
if (!bn_copy(prod_Z[0], points[0]->Z))
|
|
||||||
goto err;
|
|
||||||
} else {
|
|
||||||
if (!bn_copy(prod_Z[0], one))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i < num; i++) {
|
|
||||||
if (!BN_is_zero(points[i]->Z)) {
|
|
||||||
if (!group->meth->field_mul(group, prod_Z[i],
|
|
||||||
prod_Z[i - 1], points[i]->Z, ctx))
|
|
||||||
goto err;
|
|
||||||
} else {
|
|
||||||
if (!bn_copy(prod_Z[i], prod_Z[i - 1]))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now use a single explicit inversion to replace every non-zero
|
|
||||||
* points[i]->Z by its inverse.
|
|
||||||
*/
|
|
||||||
if (!BN_mod_inverse_nonct(tmp, prod_Z[num - 1], group->p, ctx)) {
|
|
||||||
ECerror(ERR_R_BN_LIB);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group->meth->field_encode != NULL) {
|
|
||||||
/*
|
|
||||||
* In the Montgomery case we just turned R*H (representing H)
|
|
||||||
* into 1/(R*H), but we need R*(1/H) (representing 1/H); i.e.,
|
|
||||||
* we need to multiply by the Montgomery factor twice.
|
|
||||||
*/
|
|
||||||
if (!group->meth->field_encode(group, tmp, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!group->meth->field_encode(group, tmp, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = num - 1; i > 0; i--) {
|
|
||||||
/*
|
|
||||||
* Loop invariant: tmp is the product of the inverses of
|
|
||||||
* points[0]->Z, ..., points[i]->Z (zero-valued inputs skipped).
|
|
||||||
*/
|
|
||||||
if (BN_is_zero(points[i]->Z))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* Set tmp_Z to the inverse of points[i]->Z. */
|
|
||||||
if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
/* Adjust tmp to satisfy loop invariant. */
|
|
||||||
if (!group->meth->field_mul(group, tmp, tmp, points[i]->Z, ctx))
|
|
||||||
goto err;
|
|
||||||
/* Replace points[i]->Z by its inverse. */
|
|
||||||
if (!bn_copy(points[i]->Z, tmp_Z))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!BN_is_zero(points[0]->Z)) {
|
|
||||||
/* Replace points[0]->Z by its inverse. */
|
|
||||||
if (!bn_copy(points[0]->Z, tmp))
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finally, fix up the X and Y coordinates for all points. */
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
EC_POINT *p = points[i];
|
|
||||||
|
|
||||||
if (BN_is_zero(p->Z))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
|
|
||||||
|
|
||||||
if (!group->meth->field_sqr(group, tmp, p->Z, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!group->meth->field_mul(group, p->X, p->X, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!group->meth->field_mul(group, tmp, tmp, p->Z, ctx))
|
|
||||||
goto err;
|
|
||||||
if (!group->meth->field_mul(group, p->Y, p->Y, tmp, ctx))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (!bn_copy(p->Z, one))
|
|
||||||
goto err;
|
|
||||||
p->Z_is_one = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 1;
|
|
||||||
|
|
||||||
err:
|
|
||||||
BN_CTX_end(ctx);
|
|
||||||
free(prod_Z);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ec_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
ec_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||||
BN_CTX *ctx)
|
BN_CTX *ctx)
|
||||||
|
@ -1137,7 +1005,7 @@ ec_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx)
|
||||||
#define EC_POINT_CSWAP(c, a, b, w, t) do { \
|
#define EC_POINT_CSWAP(c, a, b, w, t) do { \
|
||||||
if (!BN_swap_ct(c, (a)->X, (b)->X, w) || \
|
if (!BN_swap_ct(c, (a)->X, (b)->X, w) || \
|
||||||
!BN_swap_ct(c, (a)->Y, (b)->Y, w) || \
|
!BN_swap_ct(c, (a)->Y, (b)->Y, w) || \
|
||||||
!BN_swap_ct(c, (a)->Z, (b)->Z, w)) \
|
!BN_swap_ct(c, (a)->Z, (b)->Z, w)) \
|
||||||
goto err; \
|
goto err; \
|
||||||
t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \
|
t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \
|
||||||
(a)->Z_is_one ^= (t); \
|
(a)->Z_is_one ^= (t); \
|
||||||
|
@ -1454,16 +1322,14 @@ static const EC_METHOD ec_GFp_simple_method = {
|
||||||
.field_type = NID_X9_62_prime_field,
|
.field_type = NID_X9_62_prime_field,
|
||||||
.group_set_curve = ec_group_set_curve,
|
.group_set_curve = ec_group_set_curve,
|
||||||
.group_get_curve = ec_group_get_curve,
|
.group_get_curve = ec_group_get_curve,
|
||||||
|
.point_is_on_curve = ec_point_is_on_curve,
|
||||||
|
.point_cmp = ec_point_cmp,
|
||||||
.point_set_affine_coordinates = ec_point_set_affine_coordinates,
|
.point_set_affine_coordinates = ec_point_set_affine_coordinates,
|
||||||
.point_get_affine_coordinates = ec_point_get_affine_coordinates,
|
.point_get_affine_coordinates = ec_point_get_affine_coordinates,
|
||||||
.point_set_compressed_coordinates = ec_set_compressed_coordinates,
|
.points_make_affine = ec_points_make_affine,
|
||||||
.add = ec_add,
|
.add = ec_add,
|
||||||
.dbl = ec_dbl,
|
.dbl = ec_dbl,
|
||||||
.invert = ec_invert,
|
.invert = ec_invert,
|
||||||
.is_on_curve = ec_is_on_curve,
|
|
||||||
.point_cmp = ec_cmp,
|
|
||||||
.make_affine = ec_make_affine,
|
|
||||||
.points_make_affine = ec_points_make_affine,
|
|
||||||
.mul_generator_ct = ec_mul_generator_ct,
|
.mul_generator_ct = ec_mul_generator_ct,
|
||||||
.mul_single_ct = ec_mul_single_ct,
|
.mul_single_ct = ec_mul_single_ct,
|
||||||
.mul_double_nonct = ec_mul_double_nonct,
|
.mul_double_nonct = ec_mul_double_nonct,
|
||||||
|
@ -1482,16 +1348,14 @@ static const EC_METHOD ec_GFp_mont_method = {
|
||||||
.field_type = NID_X9_62_prime_field,
|
.field_type = NID_X9_62_prime_field,
|
||||||
.group_set_curve = ec_mont_group_set_curve,
|
.group_set_curve = ec_mont_group_set_curve,
|
||||||
.group_get_curve = ec_group_get_curve,
|
.group_get_curve = ec_group_get_curve,
|
||||||
|
.point_is_on_curve = ec_point_is_on_curve,
|
||||||
|
.point_cmp = ec_point_cmp,
|
||||||
.point_set_affine_coordinates = ec_point_set_affine_coordinates,
|
.point_set_affine_coordinates = ec_point_set_affine_coordinates,
|
||||||
.point_get_affine_coordinates = ec_point_get_affine_coordinates,
|
.point_get_affine_coordinates = ec_point_get_affine_coordinates,
|
||||||
.point_set_compressed_coordinates = ec_set_compressed_coordinates,
|
.points_make_affine = ec_points_make_affine,
|
||||||
.add = ec_add,
|
.add = ec_add,
|
||||||
.dbl = ec_dbl,
|
.dbl = ec_dbl,
|
||||||
.invert = ec_invert,
|
.invert = ec_invert,
|
||||||
.is_on_curve = ec_is_on_curve,
|
|
||||||
.point_cmp = ec_cmp,
|
|
||||||
.make_affine = ec_make_affine,
|
|
||||||
.points_make_affine = ec_points_make_affine,
|
|
||||||
.mul_generator_ct = ec_mul_generator_ct,
|
.mul_generator_ct = ec_mul_generator_ct,
|
||||||
.mul_single_ct = ec_mul_single_ct,
|
.mul_single_ct = ec_mul_single_ct,
|
||||||
.mul_double_nonct = ec_mul_double_nonct,
|
.mul_double_nonct = ec_mul_double_nonct,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/perl -T
|
#!/usr/bin/perl -T
|
||||||
|
|
||||||
# $OpenBSD: security,v 1.44 2024/12/24 17:08:50 krw Exp $
|
# $OpenBSD: security,v 1.45 2025/01/10 10:16:48 schwarze Exp $
|
||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
|
# Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
|
||||||
# Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
|
# Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
|
||||||
|
@ -456,11 +456,14 @@ sub check_mailboxes {
|
||||||
foreach my $name (readdir $dh) {
|
foreach my $name (readdir $dh) {
|
||||||
next if $name =~ /^\.\.?$/;
|
next if $name =~ /^\.\.?$/;
|
||||||
next if $name =~ /.\.lock$/;
|
next if $name =~ /.\.lock$/;
|
||||||
|
next if $name eq 'quota.user';
|
||||||
|
next if $name eq 'quota.group';
|
||||||
my ($mode, $fuid, $fgid) = (stat "$dir/$name")[2,4,5];
|
my ($mode, $fuid, $fgid) = (stat "$dir/$name")[2,4,5];
|
||||||
unless (defined $mode) {
|
unless (defined $mode) {
|
||||||
nag !$!{ENOENT}, "stat: $dir/$name: $!";
|
nag !$!{ENOENT}, "stat: $dir/$name: $!";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
next if S_ISDIR($mode);
|
||||||
my $fname = (getpwuid $fuid)[0] // $fuid;
|
my $fname = (getpwuid $fuid)[0] // $fuid;
|
||||||
my $gname = (getgrgid $fgid)[0] // $fgid;
|
my $gname = (getgrgid $fgid)[0] // $fgid;
|
||||||
nag $fname ne $name,
|
nag $fname ne $name,
|
||||||
|
|
|
@ -23,7 +23,7 @@ group rdomain2_3 {
|
||||||
descr "RDOMAIN2_3"
|
descr "RDOMAIN2_3"
|
||||||
remote-as 4200000004
|
remote-as 4200000004
|
||||||
|
|
||||||
announce extended yes
|
announce extended message yes
|
||||||
|
|
||||||
neighbor 10.12.57.4
|
neighbor 10.12.57.4
|
||||||
neighbor 2001:db8:57::4
|
neighbor 2001:db8:57::4
|
||||||
|
|
|
@ -15,7 +15,7 @@ group rdomain1 {
|
||||||
local-address 10.12.57.4
|
local-address 10.12.57.4
|
||||||
local-address 2001:db8:57::4
|
local-address 2001:db8:57::4
|
||||||
|
|
||||||
announce extended yes
|
announce extended message yes
|
||||||
|
|
||||||
neighbor 10.12.57.1
|
neighbor 10.12.57.1
|
||||||
neighbor 2001:db8:57::1
|
neighbor 2001:db8:57::1
|
||||||
|
|
117
sbin/nfsd/nfsd.c
117
sbin/nfsd/nfsd.c
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: nfsd.c,v 1.43 2025/01/02 21:37:38 kn Exp $ */
|
/* $OpenBSD: nfsd.c,v 1.44 2025/01/11 18:21:02 kn Exp $ */
|
||||||
/* $NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft Exp $ */
|
/* $NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -105,7 +105,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct nfsd_args nfsdargs;
|
struct nfsd_args nfsdargs;
|
||||||
struct sockaddr_in inetaddr;
|
struct sockaddr_in inetaddr;
|
||||||
int ch, connect_type_cnt, i;
|
int ch, i;
|
||||||
int nfsdcnt = DEFNFSDCNT, on, reregister = 0, sock;
|
int nfsdcnt = DEFNFSDCNT, on, reregister = 0, sock;
|
||||||
int udpflag = 0, tcpflag = 0, tcpsock;
|
int udpflag = 0, tcpflag = 0, tcpsock;
|
||||||
const char *errstr = NULL;
|
const char *errstr = NULL;
|
||||||
|
@ -238,40 +238,36 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Now set up the master server socket waiting for tcp connections. */
|
/* Now set up the master server socket waiting for tcp connections. */
|
||||||
on = 1;
|
on = 1;
|
||||||
connect_type_cnt = 0;
|
if (!tcpflag)
|
||||||
if (tcpflag) {
|
|
||||||
if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
|
||||||
syslog(LOG_ERR, "can't create tcp socket");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (setsockopt(tcpsock,
|
|
||||||
SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
|
|
||||||
syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %s", strerror(errno));
|
|
||||||
memset(&inetaddr, 0, sizeof inetaddr);
|
|
||||||
inetaddr.sin_family = AF_INET;
|
|
||||||
inetaddr.sin_addr.s_addr = INADDR_ANY;
|
|
||||||
inetaddr.sin_port = htons(NFS_PORT);
|
|
||||||
inetaddr.sin_len = sizeof(inetaddr);
|
|
||||||
if (bind(tcpsock, (struct sockaddr *)&inetaddr,
|
|
||||||
sizeof (inetaddr)) == -1) {
|
|
||||||
syslog(LOG_ERR, "can't bind tcp addr");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (listen(tcpsock, 5) == -1) {
|
|
||||||
syslog(LOG_ERR, "listen failed");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
|
|
||||||
!pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) {
|
|
||||||
syslog(LOG_ERR, "can't register tcp with portmap");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
connect_type_cnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect_type_cnt == 0)
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
|
syslog(LOG_ERR, "can't create tcp socket");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (setsockopt(tcpsock,
|
||||||
|
SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1)
|
||||||
|
syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %s", strerror(errno));
|
||||||
|
memset(&inetaddr, 0, sizeof inetaddr);
|
||||||
|
inetaddr.sin_family = AF_INET;
|
||||||
|
inetaddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
inetaddr.sin_port = htons(NFS_PORT);
|
||||||
|
inetaddr.sin_len = sizeof(inetaddr);
|
||||||
|
if (bind(tcpsock, (struct sockaddr *)&inetaddr,
|
||||||
|
sizeof (inetaddr)) == -1) {
|
||||||
|
syslog(LOG_ERR, "can't bind tcp addr");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (listen(tcpsock, 5) == -1) {
|
||||||
|
syslog(LOG_ERR, "listen failed");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) ||
|
||||||
|
!pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) {
|
||||||
|
syslog(LOG_ERR, "can't register tcp with portmap");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
setproctitle("master");
|
setproctitle("master");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -279,45 +275,30 @@ main(int argc, char *argv[])
|
||||||
* into the kernel for the mounts.
|
* into the kernel for the mounts.
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct pollfd pfd;
|
|
||||||
struct sockaddr_in inetpeer;
|
struct sockaddr_in inetpeer;
|
||||||
int ret, msgsock;
|
int ret, msgsock;
|
||||||
socklen_t len;
|
socklen_t len = sizeof(inetpeer);
|
||||||
|
|
||||||
pfd.fd = tcpsock;
|
if ((msgsock = accept(tcpsock,
|
||||||
pfd.events = POLLIN;
|
(struct sockaddr *)&inetpeer, &len)) == -1) {
|
||||||
|
if (errno == EWOULDBLOCK || errno == EINTR ||
|
||||||
if (connect_type_cnt > 1) {
|
errno == ECONNABORTED)
|
||||||
ret = poll(&pfd, 1, INFTIM);
|
continue;
|
||||||
if (ret < 1) {
|
syslog(LOG_ERR, "accept failed: %s", strerror(errno));
|
||||||
syslog(LOG_ERR, "poll failed: %s", strerror(errno));
|
return (1);
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
|
||||||
if (tcpflag) {
|
if (setsockopt(msgsock, SOL_SOCKET,
|
||||||
len = sizeof(inetpeer);
|
SO_KEEPALIVE, &on, sizeof(on)) == -1)
|
||||||
if ((msgsock = accept(tcpsock,
|
syslog(LOG_ERR,
|
||||||
(struct sockaddr *)&inetpeer, &len)) == -1) {
|
"setsockopt SO_KEEPALIVE: %s", strerror(errno));
|
||||||
if (errno == EWOULDBLOCK || errno == EINTR ||
|
nfsdargs.sock = msgsock;
|
||||||
errno == ECONNABORTED)
|
nfsdargs.name = (caddr_t)&inetpeer;
|
||||||
continue;
|
nfsdargs.namelen = len;
|
||||||
syslog(LOG_ERR, "accept failed: %s", strerror(errno));
|
if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) == -1) {
|
||||||
return (1);
|
syslog(LOG_ERR, "can't Add TCP socket");
|
||||||
}
|
|
||||||
memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
|
|
||||||
if (setsockopt(msgsock, SOL_SOCKET,
|
|
||||||
SO_KEEPALIVE, &on, sizeof(on)) == -1)
|
|
||||||
syslog(LOG_ERR,
|
|
||||||
"setsockopt SO_KEEPALIVE: %s", strerror(errno));
|
|
||||||
nfsdargs.sock = msgsock;
|
|
||||||
nfsdargs.name = (caddr_t)&inetpeer;
|
|
||||||
nfsdargs.namelen = sizeof(inetpeer);
|
|
||||||
if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) == -1) {
|
|
||||||
syslog(LOG_ERR, "can't Add TCP socket");
|
|
||||||
}
|
|
||||||
(void)close(msgsock);
|
|
||||||
}
|
}
|
||||||
|
(void)close(msgsock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" $OpenBSD: ruby-module.5,v 1.48 2024/11/21 06:12:23 jeremy Exp $
|
.\" $OpenBSD: ruby-module.5,v 1.49 2025/01/10 03:41:02 jeremy Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2011-2015, 2023 Jeremy Evans <jeremy@openbsd.org>
|
.\" Copyright (c) 2011-2015, 2023 Jeremy Evans <jeremy@openbsd.org>
|
||||||
.\" Copyright (c) 2008, 2011 Marc Espie <espie@openbsd.org>
|
.\" Copyright (c) 2008, 2011 Marc Espie <espie@openbsd.org>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: November 21 2024 $
|
.Dd $Mdocdate: January 10 2025 $
|
||||||
.Dt RUBY-MODULE 5
|
.Dt RUBY-MODULE 5
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -66,7 +66,7 @@ those via
|
||||||
.Ev CONFIGURE_STYLE Ns = Ns Qq ruby gem
|
.Ev CONFIGURE_STYLE Ns = Ns Qq ruby gem
|
||||||
and
|
and
|
||||||
.Ev CONFIGURE_STYLE Ns = Ns Qq ruby gem ext
|
.Ev CONFIGURE_STYLE Ns = Ns Qq ruby gem ext
|
||||||
both add ruby32 and ruby33
|
both add ruby32, ruby33, and ruby34
|
||||||
.Ev FLAVOR Ns s
|
.Ev FLAVOR Ns s
|
||||||
to the port.
|
to the port.
|
||||||
They also cause the
|
They also cause the
|
||||||
|
@ -79,10 +79,10 @@ The ports system defaults to using Ruby 3.3 if the version of Ruby is not
|
||||||
specified.
|
specified.
|
||||||
To specify a version for a gem port, use a specific
|
To specify a version for a gem port, use a specific
|
||||||
.Ev FLAVOR ,
|
.Ev FLAVOR ,
|
||||||
such as ruby32 to use Ruby 3.2.
|
such as ruby34 to use Ruby 3.4.
|
||||||
To specify the Ruby version to use for a non Ruby-gem port, set
|
To specify the Ruby version to use for a non Ruby-gem port, set
|
||||||
.Ev MODRUBY_REV
|
.Ev MODRUBY_REV
|
||||||
to 3.2 or 3.3.
|
to 3.2, 3.3, or 3.4.
|
||||||
.Pp
|
.Pp
|
||||||
To ensure that dependencies use the same Ruby implementation as the
|
To ensure that dependencies use the same Ruby implementation as the
|
||||||
current port, all Ruby gem dependencies specified in the port
|
current port, all Ruby gem dependencies specified in the port
|
||||||
|
@ -108,7 +108,7 @@ is
|
||||||
.Cm Yes ,
|
.Cm Yes ,
|
||||||
the ports system automatically adds the appropriate prefix to the
|
the ports system automatically adds the appropriate prefix to the
|
||||||
.Ev FULLPKGNAME
|
.Ev FULLPKGNAME
|
||||||
(e.g. ruby32\- for ruby 3.2, ruby33\- for ruby 3.3).
|
(e.g. ruby33\- for ruby 3.3, ruby34\- for ruby 3.4).
|
||||||
.Pp
|
.Pp
|
||||||
For Ruby gem ports that can work on multiple Ruby versions, append
|
For Ruby gem ports that can work on multiple Ruby versions, append
|
||||||
.Ev GEM_BIN_SUFFIX
|
.Ev GEM_BIN_SUFFIX
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ufshci.c,v 1.43 2024/11/09 22:41:34 jsg Exp $ */
|
/* $OpenBSD: ufshci.c,v 1.45 2025/01/11 20:48:27 mglocker Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
|
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
|
||||||
|
@ -50,11 +50,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UFSHCI_DEBUG
|
#ifdef UFSHCI_DEBUG
|
||||||
int ufshci_dbglvl = 1;
|
int ufshci_debug = 1;
|
||||||
#define DPRINTF(l, x...) do { if ((l) <= ufshci_dbglvl) printf(x); } \
|
|
||||||
while (0)
|
|
||||||
#else
|
|
||||||
#define DPRINTF(l, x...)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct cfdriver ufshci_cd = {
|
struct cfdriver ufshci_cd = {
|
||||||
|
@ -108,11 +104,15 @@ void ufshci_scsi_io_done(struct ufshci_softc *,
|
||||||
void ufshci_scsi_done(struct ufshci_softc *,
|
void ufshci_scsi_done(struct ufshci_softc *,
|
||||||
struct ufshci_ccb *);
|
struct ufshci_ccb *);
|
||||||
|
|
||||||
#if HIBERNATE
|
#ifdef HIBERNATE
|
||||||
int ufshci_hibernate_io(dev_t, daddr_t, vaddr_t, size_t,
|
int ufshci_hibernate_io(dev_t, daddr_t, vaddr_t, size_t,
|
||||||
int, void *);
|
int, void *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
void ufshci_stats_print(void *);
|
||||||
|
#endif
|
||||||
|
|
||||||
const struct scsi_adapter ufshci_switch = {
|
const struct scsi_adapter ufshci_switch = {
|
||||||
ufshci_scsi_cmd, NULL, NULL, NULL, NULL
|
ufshci_scsi_cmd, NULL, NULL, NULL, NULL
|
||||||
};
|
};
|
||||||
|
@ -125,7 +125,6 @@ ufshci_intr(void *arg)
|
||||||
int handled = 0;
|
int handled = 0;
|
||||||
|
|
||||||
status = UFSHCI_READ_4(sc, UFSHCI_REG_IS);
|
status = UFSHCI_READ_4(sc, UFSHCI_REG_IS);
|
||||||
DPRINTF(3, "%s: status=0x%08x\n", __func__, status);
|
|
||||||
|
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
return handled;
|
return handled;
|
||||||
|
@ -134,12 +133,9 @@ ufshci_intr(void *arg)
|
||||||
UFSHCI_WRITE_4(sc, UFSHCI_REG_IS, status);
|
UFSHCI_WRITE_4(sc, UFSHCI_REG_IS, status);
|
||||||
|
|
||||||
if (status & UFSHCI_REG_IS_UCCS) {
|
if (status & UFSHCI_REG_IS_UCCS) {
|
||||||
DPRINTF(3, "%s: UCCS interrupt\n", __func__);
|
|
||||||
handled = 1;
|
handled = 1;
|
||||||
}
|
}
|
||||||
if (status & UFSHCI_REG_IS_UTRCS) {
|
if (status & UFSHCI_REG_IS_UTRCS) {
|
||||||
DPRINTF(3, "%s: UTRCS interrupt\n", __func__);
|
|
||||||
|
|
||||||
ufshci_xfer_complete(sc);
|
ufshci_xfer_complete(sc);
|
||||||
|
|
||||||
handled = 1;
|
handled = 1;
|
||||||
|
@ -192,21 +188,21 @@ ufshci_attach(struct ufshci_softc *sc)
|
||||||
sc->sc_rtt = UFSHCI_REG_CAP_RTT(sc->sc_cap) + 1;
|
sc->sc_rtt = UFSHCI_REG_CAP_RTT(sc->sc_cap) + 1;
|
||||||
sc->sc_nutrs = UFSHCI_REG_CAP_NUTRS(sc->sc_cap) + 1;
|
sc->sc_nutrs = UFSHCI_REG_CAP_NUTRS(sc->sc_cap) + 1;
|
||||||
|
|
||||||
DPRINTF(1, "Capabilities (0x%08x):\n", sc->sc_cap);
|
#ifdef UFSHCI_DEBUG
|
||||||
DPRINTF(1, "CS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_CS ? 1 : 0);
|
printf("Capabilities (0x%08x):\n", sc->sc_cap);
|
||||||
DPRINTF(1, "UICDMETMS=%d\n",
|
printf(" CS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_CS ? 1 : 0);
|
||||||
sc->sc_cap & UFSHCI_REG_CAP_UICDMETMS ? 1 : 0);
|
printf(" UICDMETMS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_UICDMETMS ? 1 :0);
|
||||||
DPRINTF(1, "OODDS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_OODDS ? 1 : 0);
|
printf(" OODDS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_OODDS ? 1 : 0);
|
||||||
DPRINTF(1, "64AS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_64AS ? 1 : 0);
|
printf(" 64AS=%d\n", sc->sc_cap & UFSHCI_REG_CAP_64AS ? 1 : 0);
|
||||||
DPRINTF(1, "AUTOH8=%d\n", sc->sc_cap & UFSHCI_REG_AUTOH8 ? 1 : 0);
|
printf(" AUTOH8=%d\n", sc->sc_cap & UFSHCI_REG_AUTOH8 ? 1 : 0);
|
||||||
DPRINTF(1, "NUTMRS=%d\n", sc->sc_nutmrs);
|
printf(" NUTMRS=%d\n", sc->sc_nutmrs);
|
||||||
DPRINTF(1, "RTT=%d\n", sc->sc_rtt);
|
printf(" RTT=%d\n", sc->sc_rtt);
|
||||||
DPRINTF(1, "NUTRS=%d\n", sc->sc_nutrs);
|
printf(" NUTRS=%d\n", sc->sc_nutrs);
|
||||||
DPRINTF(1, "HCPID=0x%08x\n", sc->sc_hcpid);
|
printf(" HCPID=0x%08x\n", sc->sc_hcpid);
|
||||||
DPRINTF(1, "HCMID (0x%08x):\n", sc->sc_hcmid);
|
printf("HCMID (0x%08x):\n", sc->sc_hcmid);
|
||||||
DPRINTF(1, " BI=0x%04x\n", UFSHCI_REG_HCMID_BI(sc->sc_hcmid));
|
printf(" BI=0x%04x\n", UFSHCI_REG_HCMID_BI(sc->sc_hcmid));
|
||||||
DPRINTF(1, " MIC=0x%04x\n", UFSHCI_REG_HCMID_MIC(sc->sc_hcmid));
|
printf(" MIC=0x%04x\n", UFSHCI_REG_HCMID_MIC(sc->sc_hcmid));
|
||||||
|
#endif
|
||||||
if (sc->sc_nutrs < UFSHCI_SLOTS_MIN ||
|
if (sc->sc_nutrs < UFSHCI_SLOTS_MIN ||
|
||||||
sc->sc_nutrs > UFSHCI_SLOTS_MAX) {
|
sc->sc_nutrs > UFSHCI_SLOTS_MAX) {
|
||||||
printf("%s: Invalid NUTRS value %d (must be %d-%d)!\n",
|
printf("%s: Invalid NUTRS value %d (must be %d-%d)!\n",
|
||||||
|
@ -268,6 +264,17 @@ ufshci_attach(struct ufshci_softc *sc)
|
||||||
saa.saa_quirks = saa.saa_flags = 0;
|
saa.saa_quirks = saa.saa_flags = 0;
|
||||||
saa.saa_wwpn = saa.saa_wwnn = 0;
|
saa.saa_wwpn = saa.saa_wwnn = 0;
|
||||||
|
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
/* Collect some debugging statistics */
|
||||||
|
sc->sc_stats_slots = mallocarray(sc->sc_nutrs, sizeof(int), M_DEVBUF,
|
||||||
|
M_WAITOK | M_ZERO);
|
||||||
|
if (sc->sc_stats_slots == NULL)
|
||||||
|
printf("%s: Can't allocate stats array\n", sc->sc_dev.dv_xname);
|
||||||
|
else if (ufshci_debug > 2) {
|
||||||
|
timeout_set(&sc->sc_stats_timo, ufshci_stats_print, sc);
|
||||||
|
timeout_add_sec(&sc->sc_stats_timo, 5);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
config_found(&sc->sc_dev, &saa, scsiprint);
|
config_found(&sc->sc_dev, &saa, scsiprint);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -310,8 +317,6 @@ ufshci_is_poll(struct ufshci_softc *sc, uint32_t type)
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
int i, retry = 25;
|
int i, retry = 25;
|
||||||
|
|
||||||
DPRINTF(3, "%s\n", __func__);
|
|
||||||
|
|
||||||
for (i = 0; i < retry; i++) {
|
for (i = 0; i < retry; i++) {
|
||||||
status = UFSHCI_READ_4(sc, UFSHCI_REG_IS);
|
status = UFSHCI_READ_4(sc, UFSHCI_REG_IS);
|
||||||
if (status & type)
|
if (status & type)
|
||||||
|
@ -542,8 +547,6 @@ ufshci_doorbell_poll(struct ufshci_softc *sc, int slot, uint32_t timeout_ms)
|
||||||
uint32_t reg;
|
uint32_t reg;
|
||||||
uint64_t timeout_us;
|
uint64_t timeout_us;
|
||||||
|
|
||||||
DPRINTF(3, "%s\n", __func__);
|
|
||||||
|
|
||||||
for (timeout_us = timeout_ms * 1000; timeout_us != 0;
|
for (timeout_us = timeout_ms * 1000; timeout_us != 0;
|
||||||
timeout_us -= 1000) {
|
timeout_us -= 1000) {
|
||||||
reg = UFSHCI_READ_4(sc, UFSHCI_REG_UTRLDBR);
|
reg = UFSHCI_READ_4(sc, UFSHCI_REG_UTRLDBR);
|
||||||
|
@ -573,7 +576,6 @@ ufshci_utr_cmd_nop(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -613,7 +615,6 @@ ufshci_utr_cmd_nop(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -666,7 +667,6 @@ ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -714,7 +714,6 @@ ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -776,7 +775,6 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -822,7 +820,6 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -884,7 +881,6 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -934,7 +930,6 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -996,7 +991,6 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -1045,7 +1039,6 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -1109,7 +1102,6 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -1168,7 +1160,6 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -1208,6 +1199,10 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd),
|
bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd),
|
||||||
sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE);
|
sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE);
|
||||||
|
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
if (sc->sc_stats_slots)
|
||||||
|
sc->sc_stats_slots[slot]++;
|
||||||
|
#endif
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */
|
||||||
ccb->ccb_status = CCB_STATUS_INPROGRESS;
|
ccb->ccb_status = CCB_STATUS_INPROGRESS;
|
||||||
ufshci_doorbell_write(sc, slot);
|
ufshci_doorbell_write(sc, slot);
|
||||||
|
@ -1229,7 +1224,6 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
utrd = UFSHCI_DMA_KVA(sc->sc_dmamem_utrd);
|
||||||
utrd += slot;
|
utrd += slot;
|
||||||
memset(utrd, 0, sizeof(*utrd));
|
memset(utrd, 0, sizeof(*utrd));
|
||||||
DPRINTF(3, "%s: slot=%d\n", __func__, slot);
|
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2a) */
|
||||||
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
utrd->dw0 = UFSHCI_UTRD_DW0_CT_UFS;
|
||||||
|
@ -1279,7 +1273,6 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
|
||||||
|
|
||||||
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 3) */
|
||||||
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
dva = UFSHCI_DMA_DVA(sc->sc_dmamem_ucd) + (sizeof(*ucd) * slot);
|
||||||
DPRINTF(3, "%s: ucd dva=%llu\n", __func__, dva);
|
|
||||||
utrd->dw4 = (uint32_t)dva;
|
utrd->dw4 = (uint32_t)dva;
|
||||||
utrd->dw5 = (uint32_t)(dva >> 32);
|
utrd->dw5 = (uint32_t)(dva >> 32);
|
||||||
|
|
||||||
|
@ -1351,8 +1344,6 @@ ufshci_xfer_complete(struct ufshci_softc *sc)
|
||||||
|
|
||||||
/* 7.2.3: Mark software slot for reuse 3c) */
|
/* 7.2.3: Mark software slot for reuse 3c) */
|
||||||
ccb->ccb_status = CCB_STATUS_READY2FREE;
|
ccb->ccb_status = CCB_STATUS_READY2FREE;
|
||||||
|
|
||||||
DPRINTF(3, "slot %d completed\n", i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 7.2.3: Reset Interrupt Aggregation Counter and Timer 4) */
|
/* 7.2.3: Reset Interrupt Aggregation Counter and Timer 4) */
|
||||||
|
@ -1450,8 +1441,6 @@ ufshci_ccb_get(void *cookie)
|
||||||
struct ufshci_softc *sc = cookie;
|
struct ufshci_softc *sc = cookie;
|
||||||
struct ufshci_ccb *ccb;
|
struct ufshci_ccb *ccb;
|
||||||
|
|
||||||
DPRINTF(3, "%s\n", __func__);
|
|
||||||
|
|
||||||
mtx_enter(&sc->sc_ccb_mtx);
|
mtx_enter(&sc->sc_ccb_mtx);
|
||||||
ccb = SIMPLEQ_FIRST(&sc->sc_ccb_list);
|
ccb = SIMPLEQ_FIRST(&sc->sc_ccb_list);
|
||||||
if (ccb != NULL)
|
if (ccb != NULL)
|
||||||
|
@ -1467,8 +1456,6 @@ ufshci_ccb_put(void *cookie, void *io)
|
||||||
struct ufshci_softc *sc = cookie;
|
struct ufshci_softc *sc = cookie;
|
||||||
struct ufshci_ccb *ccb = io;
|
struct ufshci_ccb *ccb = io;
|
||||||
|
|
||||||
DPRINTF(3, "%s\n", __func__);
|
|
||||||
|
|
||||||
mtx_enter(&sc->sc_ccb_mtx);
|
mtx_enter(&sc->sc_ccb_mtx);
|
||||||
SIMPLEQ_INSERT_HEAD(&sc->sc_ccb_list, ccb, ccb_entry);
|
SIMPLEQ_INSERT_HEAD(&sc->sc_ccb_list, ccb, ccb_entry);
|
||||||
mtx_leave(&sc->sc_ccb_mtx);
|
mtx_leave(&sc->sc_ccb_mtx);
|
||||||
|
@ -1479,8 +1466,6 @@ ufshci_ccb_free(struct ufshci_softc *sc, int nccbs)
|
||||||
{
|
{
|
||||||
struct ufshci_ccb *ccb;
|
struct ufshci_ccb *ccb;
|
||||||
|
|
||||||
DPRINTF(3, "%s\n", __func__);
|
|
||||||
|
|
||||||
while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_list)) != NULL) {
|
while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_list)) != NULL) {
|
||||||
SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_list, ccb_entry);
|
SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_list, ccb_entry);
|
||||||
bus_dmamap_destroy(sc->sc_dmat, ccb->ccb_dmamap);
|
bus_dmamap_destroy(sc->sc_dmat, ccb->ccb_dmamap);
|
||||||
|
@ -1498,38 +1483,30 @@ ufshci_scsi_cmd(struct scsi_xfer *xs)
|
||||||
|
|
||||||
mtx_enter(&sc->sc_cmd_mtx);
|
mtx_enter(&sc->sc_cmd_mtx);
|
||||||
|
|
||||||
DPRINTF(3, "%s: cmd=0x%x\n", __func__, xs->cmd.opcode);
|
|
||||||
|
|
||||||
switch (xs->cmd.opcode) {
|
switch (xs->cmd.opcode) {
|
||||||
|
|
||||||
case READ_COMMAND:
|
case READ_COMMAND:
|
||||||
case READ_10:
|
case READ_10:
|
||||||
case READ_12:
|
case READ_12:
|
||||||
case READ_16:
|
case READ_16:
|
||||||
DPRINTF(3, "io read\n");
|
|
||||||
ufshci_scsi_io(xs, SCSI_DATA_IN);
|
ufshci_scsi_io(xs, SCSI_DATA_IN);
|
||||||
break;
|
break;
|
||||||
case WRITE_COMMAND:
|
case WRITE_COMMAND:
|
||||||
case WRITE_10:
|
case WRITE_10:
|
||||||
case WRITE_12:
|
case WRITE_12:
|
||||||
case WRITE_16:
|
case WRITE_16:
|
||||||
DPRINTF(3, "io write\n");
|
|
||||||
ufshci_scsi_io(xs, SCSI_DATA_OUT);
|
ufshci_scsi_io(xs, SCSI_DATA_OUT);
|
||||||
break;
|
break;
|
||||||
case SYNCHRONIZE_CACHE:
|
case SYNCHRONIZE_CACHE:
|
||||||
DPRINTF(3, "sync\n");
|
|
||||||
ufshci_scsi_sync(xs);
|
ufshci_scsi_sync(xs);
|
||||||
break;
|
break;
|
||||||
case INQUIRY:
|
case INQUIRY:
|
||||||
DPRINTF(3, "inquiry\n");
|
|
||||||
ufshci_scsi_inquiry(xs);
|
ufshci_scsi_inquiry(xs);
|
||||||
break;
|
break;
|
||||||
case READ_CAPACITY_16:
|
case READ_CAPACITY_16:
|
||||||
DPRINTF(3, "capacity16\n");
|
|
||||||
ufshci_scsi_capacity16(xs);
|
ufshci_scsi_capacity16(xs);
|
||||||
break;
|
break;
|
||||||
case READ_CAPACITY:
|
case READ_CAPACITY:
|
||||||
DPRINTF(3, "capacity\n");
|
|
||||||
ufshci_scsi_capacity(xs);
|
ufshci_scsi_capacity(xs);
|
||||||
break;
|
break;
|
||||||
case TEST_UNIT_READY:
|
case TEST_UNIT_READY:
|
||||||
|
@ -1770,10 +1747,6 @@ ufshci_scsi_io(struct scsi_xfer *xs, int dir)
|
||||||
if ((xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)) != dir)
|
if ((xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)) != dir)
|
||||||
goto error1;
|
goto error1;
|
||||||
|
|
||||||
DPRINTF(3, "%s: %s, datalen=%d (%s)\n", __func__,
|
|
||||||
ISSET(xs->flags, SCSI_DATA_IN) ? "READ" : "WRITE", xs->datalen,
|
|
||||||
ISSET(xs->flags, SCSI_POLL) ? "poll" : "no poll");
|
|
||||||
|
|
||||||
error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL,
|
error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL,
|
||||||
ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
|
ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -1892,7 +1865,7 @@ ufshci_scsi_done(struct ufshci_softc *sc, struct ufshci_ccb *ccb)
|
||||||
scsi_done(xs);
|
scsi_done(xs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HIBERNATE
|
#ifdef HIBERNATE
|
||||||
int
|
int
|
||||||
ufshci_hibernate_io(dev_t dev, daddr_t blkno, vaddr_t addr, size_t size,
|
ufshci_hibernate_io(dev_t dev, daddr_t blkno, vaddr_t addr, size_t size,
|
||||||
int op, void *page)
|
int op, void *page)
|
||||||
|
@ -2043,3 +2016,45 @@ ufshci_hibernate_io(dev_t dev, daddr_t blkno, vaddr_t addr, size_t size,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* HIBERNATE */
|
#endif /* HIBERNATE */
|
||||||
|
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
void
|
||||||
|
ufshci_stats_print(void *arg)
|
||||||
|
{
|
||||||
|
struct ufshci_softc *sc = arg;
|
||||||
|
struct ufshci_ccb *ccb;
|
||||||
|
int i;
|
||||||
|
int ready2free, inprogress, free;
|
||||||
|
|
||||||
|
ready2free = inprogress = free = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < sc->sc_nutrs; i++) {
|
||||||
|
ccb = &sc->sc_ccbs[i];
|
||||||
|
|
||||||
|
switch (ccb->ccb_status) {
|
||||||
|
case CCB_STATUS_FREE:
|
||||||
|
free++;
|
||||||
|
break;
|
||||||
|
case CCB_STATUS_INPROGRESS:
|
||||||
|
inprogress++;
|
||||||
|
break;
|
||||||
|
case CCB_STATUS_READY2FREE:
|
||||||
|
ready2free++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("unknown ccb status 0x%x!\n", ccb->ccb_status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("ccbs free : %02d\n", free);
|
||||||
|
printf("ccbs in-progress : %02d\n", inprogress);
|
||||||
|
printf("ccbs ready2free : %02d\n", ready2free);
|
||||||
|
|
||||||
|
for (i = 0; i < sc->sc_nutrs; i++) {
|
||||||
|
printf("ccb slot %02d i/o operations : %d\n",
|
||||||
|
i, sc->sc_stats_slots[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout_add_sec(&sc->sc_stats_timo, 5);
|
||||||
|
}
|
||||||
|
#endif /* UFSHCI_DEBUG */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: ufshcivar.h,v 1.10 2024/10/08 00:46:29 jsg Exp $ */
|
/* $OpenBSD: ufshcivar.h,v 1.11 2025/01/11 20:48:27 mglocker Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
|
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
|
||||||
|
@ -16,6 +16,15 @@
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* #define UFSHCI_DEBUG */
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
extern int ufshci_debug;
|
||||||
|
#define DPRINTF(l, x...) do { if ((l) <= ufshci_debug) printf(x); } \
|
||||||
|
while (0)
|
||||||
|
#else
|
||||||
|
#define DPRINTF(l, x...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UFSHCI_READ_4(sc, x) \
|
#define UFSHCI_READ_4(sc, x) \
|
||||||
bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (x))
|
bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (x))
|
||||||
#define UFSHCI_WRITE_4(sc, x, y) \
|
#define UFSHCI_WRITE_4(sc, x, y) \
|
||||||
|
@ -79,6 +88,12 @@ struct ufshci_softc {
|
||||||
struct mutex sc_ccb_mtx;
|
struct mutex sc_ccb_mtx;
|
||||||
struct ufshci_ccb_list sc_ccb_list;
|
struct ufshci_ccb_list sc_ccb_list;
|
||||||
struct ufshci_ccb *sc_ccbs;
|
struct ufshci_ccb *sc_ccbs;
|
||||||
|
|
||||||
|
#ifdef UFSHCI_DEBUG
|
||||||
|
/* Debugging statistics */
|
||||||
|
struct timeout sc_stats_timo;
|
||||||
|
int *sc_stats_slots;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
int ufshci_intr(void *);
|
int ufshci_intr(void *);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: tcp_input.c,v 1.421 2025/01/09 16:47:24 bluhm Exp $ */
|
/* $OpenBSD: tcp_input.c,v 1.422 2025/01/10 20:19:03 bluhm Exp $ */
|
||||||
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
|
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1970,7 +1970,7 @@ dodata: /* XXX */
|
||||||
m_freem(m);
|
m_freem(m);
|
||||||
else {
|
else {
|
||||||
m_adj(m, hdroptlen);
|
m_adj(m, hdroptlen);
|
||||||
mtx_enter(&so->so_rcv.sb_mtx);
|
mtx_enter(&so->so_rcv.sb_mtx);
|
||||||
sbappendstream(so, &so->so_rcv, m);
|
sbappendstream(so, &so->so_rcv, m);
|
||||||
mtx_leave(&so->so_rcv.sb_mtx);
|
mtx_leave(&so->so_rcv.sb_mtx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue