congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
DHParameters
Code IndexAdd Tabnine to your IDE (free)

How to use
DHParameters
in
org.spongycastle.crypto.params

Best Java code snippets using org.spongycastle.crypto.params.DHParameters (Showing top 20 results out of 315)

origin: com.madgag.spongycastle/prov

JCEDHPublicKey(
  DHPublicKeyParameters  params)
{
  this.y = params.getY();
  this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL());
}
origin: com.madgag.spongycastle/core

private static DHParameters fromSafeP(String hexP)
{
  BigInteger p = fromHex(hexP), q = p.shiftRight(1);
  return new DHParameters(p, TWO, q);
}
origin: com.madgag.spongycastle/core

public static boolean areCompatibleParameters(DHParameters a, DHParameters b)
{
  return a.getP().equals(b.getP()) && a.getG().equals(b.getG())
    && (a.getQ() == null || b.getQ() == null || a.getQ().equals(b.getQ()));
}
origin: com.madgag.spongycastle/core

  static int getStrength(DHParameters params)
  {
    return params.getL() != 0 ? params.getL() : params.getP().bitLength();
  }
}
origin: com.madgag/sc-light-jdk15on

protected boolean areCompatibleParameters(DHParameters a, DHParameters b)
{
  return a.getP().equals(b.getP()) && a.getG().equals(b.getG());
}
origin: com.madgag/sc-light-jdk15on

BigInteger calculatePrivate(DHParameters dhParams, SecureRandom random)
{
  BigInteger p = dhParams.getP();
  int limit = dhParams.getL();
  if (limit != 0)
  {
    return new BigInteger(limit, random).setBit(limit - 1);
  }
  BigInteger min = TWO;
  int m = dhParams.getM();
  if (m != 0)
  {
    min = ONE.shiftLeft(m - 1);
  }
  BigInteger max = p.subtract(TWO);
  BigInteger q = dhParams.getQ();
  if (q != null)
  {
    max = q.subtract(TWO);
  }
  return BigIntegers.createRandomInRange(min, max, random);
}
origin: com.madgag.spongycastle/core

public int getFieldSize()
{
  return (key.getParameters().getP().bitLength() + 7) / 8;
}
origin: com.madgag/sc-light-jdk15on

  /**
   * given a short term public key from a given party calculate the next
   * message in the agreement sequence. 
   */
  public BigInteger calculateAgreement(
    CipherParameters   pubKey)
  {
    DHPublicKeyParameters   pub = (DHPublicKeyParameters)pubKey;

    if (!pub.getParameters().equals(dhParams))
    {
      throw new IllegalArgumentException("Diffie-Hellman public key has wrong parameters.");
    }

    return pub.getY().modPow(key.getX(), dhParams.getP());
  }
}
origin: com.madgag.spongycastle/core

private BigInteger validate(BigInteger y, DHParameters dhParams)
{
  if (y == null)
  {
    throw new NullPointerException("y value cannot be null");
  }
  // TLS check
  if (y.compareTo(TWO) < 0 || y.compareTo(dhParams.getP().subtract(TWO)) > 0)
  {
    throw new IllegalArgumentException("invalid DH public key");
  }
  if (dhParams.getQ() != null)
  {
    if (ONE.equals(y.modPow(dhParams.getQ(), dhParams.getP())))
    {
      return y;
    }
    throw new IllegalArgumentException("Y value does not appear to be in correct group");
  }
  else
  {
    return y;         // we can't validate without Q.
  }
}
origin: com.madgag/sc-light-jdk15on

  public int hashCode()
  {
    int code = isPrivate() ? 0 : 1;
    
    if (params != null)
    {
      code ^= params.hashCode();
    }
    
    return code;
  }
}
origin: com.madgag/sc-light-jdk15on

public DHParameters(
  BigInteger  p,
  BigInteger  g,
  BigInteger  q,
  int         l)
{
  this(p, g, q, getDefaultMParam(l), l, null, null);
}
origin: com.madgag.spongycastle/core

public boolean equals(
  Object  obj)
{
  if (!(obj instanceof DHKeyParameters))
  {
    return false;
  }
  DHKeyParameters    dhKey = (DHKeyParameters)obj;
  if (params == null)
  {
    return dhKey.getParameters() == null;
  }
  else
  { 
    return params.equals(dhKey.getParameters());
  }
}

origin: com.madgag.spongycastle/core

  BigInteger calculatePublic(DHParameters dhParams, BigInteger x)
  {
    return dhParams.getG().modPow(x, dhParams.getP());
  }
}
origin: com.madgag.spongycastle/core

BigInteger calculatePrivate(DHParameters dhParams, SecureRandom random)
  int limit = dhParams.getL();
  int m = dhParams.getM();
  if (m != 0)
  BigInteger q = dhParams.getQ();
  if (q == null)
    q = dhParams.getP();
origin: com.madgag.spongycastle/core

  public AsymmetricKeyParameter readKey(InputStream stream)
    throws IOException
  {
    byte[] V = new byte[(dhParams.getP().bitLength() + 7) / 8];

    Streams.readFully(stream, V, 0, V.length);

    return new DHPublicKeyParameters(new BigInteger(1, V), dhParams);
  }
}
origin: com.madgag/sc-light-jdk15on

  /**
   * given a message from a given party and the corresponding public key,
   * calculate the next message in the agreement sequence. In this case
   * this will represent the shared secret.
   */
  public BigInteger calculateAgreement(
    DHPublicKeyParameters   pub,
    BigInteger              message)
  {
    if (!pub.getParameters().equals(dhParams))
    {
      throw new IllegalArgumentException("Diffie-Hellman public key has wrong parameters.");
    }

    BigInteger p = dhParams.getP();

    return message.modPow(key.getX(), p).multiply(pub.getY().modPow(privateValue, p)).mod(p);
  }
}
origin: com.madgag/sc-light-jdk15on

  static int getStrength(DHParameters params)
  {
    return params.getL() != 0 ? params.getL() : params.getP().bitLength();
  }
}
origin: casific/murmur

BigInteger xInverse = x.modInverse(DH_GROUP_PARAMETERS.getQ());
BigInteger i = iDoubleBlind.modPow(xInverse, DH_GROUP_PARAMETERS.getP());
origin: com.madgag.spongycastle/core

  public int hashCode()
  {
    int code = isPrivate() ? 0 : 1;
    
    if (params != null)
    {
      code ^= params.hashCode();
    }
    
    return code;
  }
}
origin: com.madgag.spongycastle/core

public DHParameters(
  BigInteger  p,
  BigInteger  g,
  BigInteger  q,
  int         l)
{
  this(p, g, q, getDefaultMParam(l), l, null, null);
}
org.spongycastle.crypto.paramsDHParameters

Most used methods

  • getG
  • getP
  • <init>
  • getL
    Return the private value length in bits - if set, zero otherwise
  • getQ
  • equals
  • getDefaultMParam
  • getM
    Return the minimum length of the private value.
  • hashCode

Popular in Java

  • Start an intent from android
  • getContentResolver (Context)
  • runOnUiThread (Activity)
  • setRequestProperty (URLConnection)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Collectors (java.util.stream)
  • Runner (org.openjdk.jmh.runner)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now