-
- if (ecxctx->key == NULL
- || ecxctx->key->privkey == NULL
- || ecxctx->peerkey == NULL) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
- return 0;
- }
-
- if (!ossl_assert(ecxctx->keylen == X25519_KEYLEN
- || ecxctx->keylen == X448_KEYLEN)) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
- return 0;
- }
-
- if (secret == NULL) {
- *secretlen = ecxctx->keylen;
- return 1;
- }
- if (outlen < ecxctx->keylen) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
- return 0;
- }
-
- if (ecxctx->keylen == X25519_KEYLEN) {
-#ifdef S390X_EC_ASM
- if (OPENSSL_s390xcap_P.pcc[1]
- & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519)) {
- if (s390x_x25519_mul(secret, ecxctx->peerkey->pubkey,
- ecxctx->key->privkey) == 0) {
- ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
- return 0;
- }
- } else
-#endif
- if (X25519(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
- ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
- return 0;
- }
- } else {
-#ifdef S390X_EC_ASM
- if (OPENSSL_s390xcap_P.pcc[1]
- & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448)) {
- if (s390x_x448_mul(secret, ecxctx->peerkey->pubkey,
- ecxctx->key->privkey) == 0) {
- ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
- return 0;
- }
- } else
-#endif
- if (X448(secret, ecxctx->key->privkey, ecxctx->peerkey->pubkey) == 0) {
- ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
- return 0;
- }
- }
-
- *secretlen = ecxctx->keylen;
- return 1;