void ne7ssh_crypt::computeMac (Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32 seq) { SecureVector<Botan::byte> macStr; uint32 nSeq = htonl (seq); if (hmacIn) { macStr = Botan::SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4); macStr += packet; hmac = hmacIn->process (macStr); } else hmac.clear(); }
void ne7ssh_string::bn2vector(Botan::SecureVector<Botan::byte>& result, const Botan::BigInt& bi) { int high; Botan::byte zero = '\0'; SecureVector<Botan::byte> strVector = BigInt::encode(bi); high = (*(strVector.begin()) & 0x80) ? 1 : 0; if (high) { result = SecureVector<Botan::byte>(&zero, 1); } else { result.clear(); } result += strVector; }
bool ne7ssh_crypt::agree (Botan::SecureVector<Botan::byte> &result, const char* local, Botan::SecureVector<Botan::byte> &remote) { ne7ssh_string localAlgos (local, 0); ne7ssh_string remoteAlgos (remote, 0); char* localAlgo, *remoteAlgo; bool match; size_t len; localAlgos.split (','); localAlgos.resetParts(); remoteAlgos.split (','); remoteAlgos.resetParts(); match = false; while ((localAlgo = localAlgos.nextPart())) { len = strlen(localAlgo); while ((remoteAlgo = remoteAlgos.nextPart())) { if (!memcmp (localAlgo, remoteAlgo, len)) { match = true; break; } } if (match) break; remoteAlgos.resetParts(); } if (match) { result = Botan::SecureVector<Botan::byte>((Botan::byte*)localAlgo, (uint32_t) len); return true; } else { result.clear(); return false; } }