Exemple #1
0
def checkPadding(rawCipher, rawIV):
    rawOutput = aes_cbc_dec(rawCipher, aeskey, rawIV);
    try:
        checkAndRemovePKCS7Padding(rawOutput);
        return True;
    except:
        return False;
def message5_5_gp1(state):
    # (p-1) is essentially (-1)
    # B's secret is (-1)^b which is either (+1) or (-1) (and also B)
    # A's secret is (-1)^b^a, which is either (+1) or (-1),
    # but not necessarily the same as B's secret
    # thus, we may need to modify cipher
    # use CBC padding to check validity of key
    # check validity of cbc padding to determine which
    # B's secret 
    cipherkey_plus1, mackey_plus1 = secretToKeys(intToBytes(1));
    cipherkey_minus1, mackey_minus1 = secretToKeys(intToBytes(state["p"]-1));
    plain_plus1 = aes_cbc_dec(state["a_cipher"], cipherkey_plus1, state["a_iv"])
    plain_minus1 = aes_cbc_dec(state["a_cipher"], cipherkey_minus1, state["a_iv"])
    plain = None;
    try:
        plain = checkAndRemovePKCS7Padding(plain_plus1)
        state["m_key_a"] = cipherkey_plus1
    except ValueError:
        plain = checkAndRemovePKCS7Padding(plain_minus1)
        state["m_key_a"] = cipherkey_minus1
    state["m_plain_a"] = plain;
    # encrypt to B's key
    state["m_key_b"], b_mackey = secretToKeys(intToBytes(state["B"]))
    state["a_cipher"] = aes_cbc_enc(addPKCS7Padding(plain, 16), state["m_key_b"], state["a_iv"]);
    return state;
Exemple #3
0
def message5_5_gp1(state):
    # (p-1) is essentially (-1)
    # B's secret is (-1)^b which is either (+1) or (-1) (and also B)
    # A's secret is (-1)^b^a, which is either (+1) or (-1),
    # but not necessarily the same as B's secret
    # thus, we may need to modify cipher
    # use CBC padding to check validity of key
    # check validity of cbc padding to determine which
    # B's secret
    cipherkey_plus1, mackey_plus1 = secretToKeys(intToBytes(1))
    cipherkey_minus1, mackey_minus1 = secretToKeys(intToBytes(state["p"] - 1))
    plain_plus1 = aes_cbc_dec(state["a_cipher"], cipherkey_plus1,
                              state["a_iv"])
    plain_minus1 = aes_cbc_dec(state["a_cipher"], cipherkey_minus1,
                               state["a_iv"])
    plain = None
    try:
        plain = checkAndRemovePKCS7Padding(plain_plus1)
        state["m_key_a"] = cipherkey_plus1
    except ValueError:
        plain = checkAndRemovePKCS7Padding(plain_minus1)
        state["m_key_a"] = cipherkey_minus1
    state["m_plain_a"] = plain
    # encrypt to B's key
    state["m_key_b"], b_mackey = secretToKeys(intToBytes(state["B"]))
    state["a_cipher"] = aes_cbc_enc(addPKCS7Padding(plain, 16),
                                    state["m_key_b"], state["a_iv"])
    return state
Exemple #4
0
def decryptAndCheckAdmin(cip):
    rawPlain = checkAndRemovePKCS7Padding(aes_cbc_dec(cip, global_aes_key, global_iv));
    strPlain = str(rawPlain).rstrip("b'");
    print(strPlain)
    if ";admin=true;" in strPlain:
        return True;
    return False;
Exemple #5
0
def decryptAndCheckAdmin(cip):
    rawPlain = checkAndRemovePKCS7Padding(
        aes_cbc_dec(cip, global_aes_key, global_iv))
    strPlain = str(rawPlain).rstrip("b'")
    print(strPlain)
    if ";admin=true;" in strPlain:
        return True
    return False