/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <jni.h>
#include "impl/ecc_impl.h"
#define INVALID_ALGORITHM_PARAMETER_EXCEPTION \
#define INVALID_PARAMETER_EXCEPTION \
extern "C" {
/*
* Throws an arbitrary Java exception.
*/
{
}
/*
* Deep free of the ECParams struct
*/
{
// Use B_FALSE to free the SECItem->data element, but not the SECItem itself
// Use B_TRUE to free both
if (freeStruct)
}
/*
* Class: sun_security_ec_ECKeyPairGenerator
* Method: generateECKeyPair
* Signature: (I[B[B)[J
*/
{
// Initialize the ECParams struct
// Fill a new ECParams using the supplied OID
/* bad curve OID */
goto cleanup;
}
// Copy seed from Java to native buffer
// Generate the new keypair (using the supplied seed)
jSeedLength, 0) != SECSuccess) {
goto cleanup;
}
// If the array is a copy then we must write back our changes
}
{
if (params_item.data)
if (ecparams)
FreeECParams(ecparams, true);
if (privKey) {
// Don't free privKey->privateValue and privKey->publicValue
}
if (pSeedBuffer)
delete [] pSeedBuffer;
}
return result;
}
/*
* Class: sun_security_ec_ECKeyPairGenerator
* Method: getEncodedBytes
* Signature: (J)[B
*/
{
// Copy bytes from a native SECItem buffer to Java byte array
// Use B_FALSE to free only the SECItem->data
SECITEM_FreeItem(s, B_FALSE);
return jEncodedBytes;
}
/*
* Class: sun_security_ec_ECDSASignature
* Method: signDigest
* Signature: ([B[B[B[B)[B
*/
(JNIEnv *env, jclass clazz, jbyteArray digest, jbyteArray privateKey, jbyteArray encodedParams, jbyteArray seed)
{
// Copy digest from Java to native buffer
// Initialize the ECParams struct
// Fill a new ECParams using the supplied OID
/* bad curve OID */
goto cleanup;
}
// Extract private key data
// Prepare a buffer for the signature (twice the key length)
// Copy seed from Java to native buffer
// Sign the digest (using the supplied seed)
goto cleanup;
}
// Create new byte array
// Copy data from native buffer
{
if (params_item.data)
if (pDigestBuffer)
delete [] pDigestBuffer;
if (pSignedDigestBuffer)
delete [] pSignedDigestBuffer;
if (pSeedBuffer)
delete [] pSeedBuffer;
if (ecparams)
FreeECParams(ecparams, true);
}
return jSignedDigest;
}
/*
* Class: sun_security_ec_ECDSASignature
* Method: verifySignedDigest
* Signature: ([B[B[B[B)Z
*/
(JNIEnv *env, jclass clazz, jbyteArray signedDigest, jbyteArray digest, jbyteArray publicKey, jbyteArray encodedParams)
{
// Copy signedDigest from Java to native buffer
// Copy digest from Java to native buffer
// Extract public key data
// Initialize the ECParams struct
// Fill a new ECParams using the supplied OID
/* bad curve OID */
goto cleanup;
}
!= SECSuccess) {
goto cleanup;
}
isValid = true;
{
if (params_item.data)
if (ecparams)
FreeECParams(ecparams, true);
if (pSignedDigestBuffer)
delete [] pSignedDigestBuffer;
if (pDigestBuffer)
delete [] pDigestBuffer;
}
return isValid;
}
/*
* Class: sun_security_ec_ECDHKeyAgreement
* Method: deriveKey
* Signature: ([B[B[B)[B
*/
{
// Extract private key value
// Extract public key value
// Initialize the ECParams struct
// Fill a new ECParams using the supplied OID
/* bad curve OID */
goto cleanup;
}
// Prepare a buffer for the secret
&secret_item, 0) != SECSuccess) {
goto cleanup;
}
// Create new byte array
// Copy bytes from the SECItem buffer to a Java byte array
// Free the SECItem data buffer
{
if (privateValue_item.data)
if (publicValue_item.data)
if (params_item.data)
if (ecparams)
FreeECParams(ecparams, true);
}
return jSecret;
}
} /* extern "C" */