Пример #1
0
  private void send_client_DH_inner_data(long retry_id) {
    byte[] b_data = new byte[256];
    Common.random.nextBytes(b_data);

    BigInteger b = new BigInteger(1, b_data);
    BigInteger g_b = g.modPow(b, dh_prime);
    Common.logError(
        "g_b length: " + g_b.toByteArray().length + " -> " + Common.toBytes(g_b).length);

    BigInteger akey = g_a.modPow(b, dh_prime);
    Common.logError("auth_key: " + akey.toString());
    setAuthKey(Common.toBytes(akey));

    // gen data (client_DH_inner_data)
    TL.Object data_obj = TL.newObject("client_DH_inner_data", cl_nonce, sv_nonce, retry_id, g_b);
    byte[] data = data_obj.serialize();
    byte[] hash = Common.getSHA1(data);

    byte[] data_with_hash = new byte[(hash.length + data.length + 15) / 16 * 16];
    System.arraycopy(hash, 0, data_with_hash, 0, hash.length);
    System.arraycopy(data, 0, data_with_hash, hash.length, data.length);

    // send set_client_DH_params
    TL.Object req_obj =
        TL.newObject("set_client_DH_params", cl_nonce, sv_nonce, aes.IGE(data_with_hash, true));
    send(req_obj, false, false);
  }
Пример #2
0
  private void TL_ResPQ(TL.Object obj) {
    sv_nonce = obj.getBytes("server_nonce");
    BigInteger pq = new BigInteger(1, obj.getBytes("pq"));
    TL.Vector v_fp = obj.getVector("server_public_key_fingerprints");
    fp = v_fp.getLong(0);
    Common.logError("pq: " + pq.toString());

    // prime factorization for pq
    BigInteger q = Common.rho(pq);
    BigInteger p = pq.divide(q);
    if (p.compareTo(q) > 0) {
      BigInteger t = p;
      p = q;
      q = t;
    }
    SecureRandom rnd = new SecureRandom();
    new_nonce = new byte[32];
    rnd.nextBytes(new_nonce);

    // generate encrypted_data
    TL.Object data_obj = TL.newObject("p_q_inner_data", pq, p, q, cl_nonce, sv_nonce, new_nonce);

    byte[] data = data_obj.serialize();
    byte[] hash = Common.getSHA1(data);

    byte[] data_with_hash = new byte[255];
    System.arraycopy(hash, 0, data_with_hash, 0, hash.length);
    System.arraycopy(data, 0, data_with_hash, hash.length, data.length);
    GEN_random_bytes(data_with_hash, data.length + hash.length, 255);

    byte[] encrypted_data = Common.RSA(RSA_MODULUS, RSA_EXPONENT, data_with_hash);

    // req_DH_params
    TL.Object req_obj = TL.newObject("req_DH_params", cl_nonce, sv_nonce, p, q, fp, encrypted_data);
    send(req_obj, false, false);
  }