Skip to content

Commit

Permalink
Merge pull request #309 from aligungr/dev
Browse files Browse the repository at this point in the history
Release v3.1.8
  • Loading branch information
aligungr authored May 1, 2021
2 parents fa98105 + 1d85281 commit 7d5fe2d
Show file tree
Hide file tree
Showing 25 changed files with 555 additions and 187 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="https://github.com/aligungr/UERANSIM"><img src="/.github/logo.png" width="75" title="UERANSIM"></a>
</p>
<p align="center">
<img src="https://img.shields.io/badge/UERANSIM-v3.1.7-blue" />
<img src="https://img.shields.io/badge/UERANSIM-v3.1.8-blue" />
<img src="https://img.shields.io/badge/3GPP-R15-orange" />
<img src="https://img.shields.io/badge/License-GPL--3.0-green"/>
</p>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypt/milenage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Milenage Calculate(const OctetString &opc, const OctetString &key, const OctetSt
r.ak_r = OctetString::FromSpare(6);

if (milenage_f1(opc.data(), key.data(), rand.data(), sqn.data(), amf.data(), r.mac_a.data(), r.mac_s.data()))
throw std::runtime_error("OPC calculation failed");
throw std::runtime_error("Milenage calculation failed");
if (milenage_f2345(opc.data(), key.data(), rand.data(), r.res.data(), r.ck.data(), r.ik.data(), r.ak.data(),
r.ak_r.data()))
throw std::runtime_error("OPC calculation failed");
throw std::runtime_error("Milenage calculation failed");

return r;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/nas/msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ struct SecurityModeCommand : PlainMmMessage
std::optional<IES1UeNetworkCapability> replayedS1UeNetworkCapability{};

octet4 _macForNewSC{};
OctetString _originalPlainNasPdu{};

SecurityModeCommand();
void onBuild(NasMessageBuilder &b);
Expand Down
17 changes: 16 additions & 1 deletion src/ue/nas/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ std::pair<OctetString, OctetString> CalculateCkPrimeIkPrime(const OctetString &c
s[1] = sqnXorAk.copy();

auto res = crypto::CalculateKdfKey(key, 0x20, s, 2);
;

std::pair<OctetString, OctetString> ckIk;
ckIk.first = res.subCopy(0, ck.length());
Expand Down Expand Up @@ -139,4 +138,20 @@ OctetString CalculateResStar(const OctetString &key, const std::string &snn, con
return output.subCopy(output.length() - 16);
}

OctetString DeriveAmfPrimeInMobility(bool isUplink, const NasCount &count, const OctetString &kAmf)
{
OctetString params[2];
params[0] = OctetString::FromOctet(isUplink ? 0x00 : 0x01);
params[1] = OctetString::FromOctet4(count.toOctet4());

return crypto::CalculateKdfKey(kAmf, 0x72, params, 2);
}

OctetString CalculateAuts(const OctetString &sqn, const OctetString &ak, const OctetString &macS)
{
OctetString auts = OctetString::Xor(sqn, ak);
auts.append(macS);
return auts;
}

} // namespace nr::ue::keys
12 changes: 11 additions & 1 deletion src/ue/nas/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ void DeriveNasKeys(NasSecurityContext &securityContext);
*/
std::string ConstructServingNetworkName(const Plmn &plmn);

/**
* Derives kAMF to kAMF' in mobility 33.501/A.13
*/
OctetString DeriveAmfPrimeInMobility(bool isUplink, const NasCount &count, const OctetString &kAmf);

/**
* Calculates K_AUSF for 5G-AKA according to given parameters as specified in 3GPP TS 33.501 Annex A.2
*/
Expand Down Expand Up @@ -66,4 +71,9 @@ OctetString CalculateKAusfForEapAkaPrime(const OctetString &mk);
OctetString CalculateResStar(const OctetString &key, const std::string &snn, const OctetString &rand,
const OctetString &res);

} // namespace nr::ue::keys
/*
* Calculates AUTS according to the given parameters
*/
OctetString CalculateAuts(const OctetString &sqn, const OctetString &ak, const OctetString &macS);

} // namespace nr::ue::keys
Loading

0 comments on commit 7d5fe2d

Please sign in to comment.