Giter Club home page Giter Club logo

Comments (4)

licel avatar licel commented on July 20, 2024

We are actively working on the implementation of the absent functionality of 3.0.4/3.0.5 - ALG_EC_SVDP_DH_PLAIN is slightly different from ALG_EC_SVDP_DH, and we will need to check the implementation on a card, I think within a couple of days this algorithm will be supported in jCardSim.

from jcardsim.

paulbastian avatar paulbastian commented on July 20, 2024

I wrote a standalone version recently (tested) and imported that to the KeyAgreementImpl (untested):
Have a try.

public class KeyAgreementImpl extends KeyAgreement {
    BasicAgreement engine;
    SHA1Digest digestEngine;
    byte algorithm;
    ECPrivateKeyImpl privateKey;

    public KeyAgreementImpl(byte algorithm) {
        this.algorithm = algorithm;
        switch(algorithm) {
        case 1:
            this.engine = new ECDHBasicAgreement();
            this.digestEngine = new SHA1Digest();
            break;
        case 2:
            this.engine = new ECDHCBasicAgreement();
            this.digestEngine = new SHA1Digest();
            break;
        case 3:
            this.engine = new ECDHBasicAgreement();
            this.digestEngine = null;
            break;
        default:
            CryptoException.throwIt((short)3);
        }  
    }

    public void init(PrivateKey privateKey) throws CryptoException {
        if(privateKey == null) {
            CryptoException.throwIt((short)2);
        }

        if(!(privateKey instanceof ECPrivateKeyImpl)) {
            CryptoException.throwIt((short)1);
        }

        this.engine.init(((ECPrivateKeyImpl)privateKey).getParameters());
        this.privateKey = (ECPrivateKeyImpl)privateKey;
    }

    public byte getAlgorithm() {
        return this.algorithm;
    }

    public short generateSecret(byte[] publicData, short publicOffset, short publicLength, byte[] secret, short secretOffset) throws CryptoException {
        byte[] publicKey = new byte[publicLength];
        Util.arrayCopyNonAtomic(publicData, publicOffset, publicKey, (short)0, publicLength);
        ECPublicKeyParameters ecp = new ECPublicKeyParameters(((ECPrivateKeyParameters)this.privateKey.getParameters()).getParameters().getCurve().decodePoint(publicKey), ((ECPrivateKeyParameters)this.privateKey.getParameters()).getParameters());
        byte[] result = this.engine.calculateAgreement(ecp).toByteArray();

        switch(algorithm) {
        case 1:
        case 2:
            byte[] hashResult = new byte[20];
            this.digestEngine.update(result, 0, result.length);
            this.digestEngine.doFinal(hashResult, 0);
            Util.arrayCopyNonAtomic(hashResult, (short)0, secret, secretOffset, (short)hashResult.length);
            return (short)hashResult.length;
        case 3:
            Util.arrayCopyNonAtomic(result, (short)0, secret, secretOffset, (short)result.length);
            return (short)result.length;
        default:
            CryptoException.throwIt((short)3);
        }  
    }
}

from jcardsim.

petrs avatar petrs commented on July 20, 2024

J08nY opened pull request #121 implementing ALG_EC_SVDP_DH_PLAIN_XY

from jcardsim.

J08nY avatar J08nY commented on July 20, 2024

@licel DH_PLAIN is now implemented along with DHC_PLAIN and DH_PLAIN_XY so this can be closed.

from jcardsim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.