https://github.com/wmnsk/milenage
MILENAGE algorithm implemented in the Go Programming Language.
https://github.com/wmnsk/milenage
epc eutran lte milenage security telecom
Last synced: 4 months ago
JSON representation
MILENAGE algorithm implemented in the Go Programming Language.
- Host: GitHub
- URL: https://github.com/wmnsk/milenage
- Owner: wmnsk
- License: mit
- Created: 2018-12-11T09:24:54.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-25T18:02:21.000Z (about 1 year ago)
- Last Synced: 2025-04-25T19:20:11.386Z (about 1 year ago)
- Topics: epc, eutran, lte, milenage, security, telecom
- Language: Go
- Size: 70.3 KB
- Stars: 13
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-telco - milenage (Go) - 12]` - MILENAGE algorithm implementation in Go for 3G/4G/5G AKA authentication. (Protocols / NAS 4G/5G and Milenage)
README
# MILENAGE
MILENAGE algorithm implemented in the Go Programming Language.
[](https://github.com/wmnsk/milenage/actions/workflows/go.yml)
[](https://github.com/wmnsk/milenage/actions/workflows/golangci-lint.yml)
[](https://pkg.go.dev/github.com/wmnsk/milenage)
[](https://github.com/wmnsk/milenage/blob/main/LICENSE)
## Quickstart
Initialize Milenage first with K, OP, RAND, SQN, and AMF.
```go
mil := milenage.New(
// K
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
// OP
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
// RAND
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
0x000000000001, // SQN
0x8000, // AMF
)
```
Or, with OPc.
```go
mil := milenage.NewWithOPc(
// K
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
// OPc
[]byte{0x62, 0xe7, 0x5b, 0x8d, 0x6f, 0xa5, 0xbf, 0x46, 0xec, 0x87, 0xa9, 0x27, 0x6f, 0x9d, 0xf5, 0x4d},
// RAND
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
0x000000000001, // SQN
0x8000, // AMF
)
```
Get MAC-A and MAC-S. This also fills each field.
```go
macA, err := mil.F1()
if err != nil {
// ...
}
macS, err := mil.F1Star()
if err != nil {
// ...
}
```
Get RES, CK, IK, AK. This also fills each field.
```go
res, ck, ik, ak, err := mil.F2345()
if err != nil {
// ...
}
```
Get RES* for 5G with `ComputeRESStar()` by giving MCC and MNC.
```go
resStar, err := mil.ComputeRESStar("001", "01")
if err != nil {
// ...
}
```
Get OPc from K and OP. This is not the method on `*Milenage`. An example program can be found [here](./examples/compute_opc).
```go
opc, err := milenage.ComputeOPc(
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
[]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
)
if err != nil {
// ...
}
```
Get AUTN and AUTS which are used in authentication procedure.
Be sure that the required calculation has done before calling these methods.
```go
autn, err := mil.GenerateAUTN()
if err != nil {
// ...
}
// Note that this re-calcurates MAC-S and AKS with AMF=0x0000
// as described in 6.3.3, TS 33.102.
auts, err := mil.GenerateAUTS()
if err != nil {
// ...
}
```
Fill all fields(except 5G RES*) at once using `ComputeAll()`.
Be sure that this uses the bare AMF value in `*Milenage` and the MAC-S value might be a unwanted one.
Call each function with the right parameters to get the right values.
```go
if err := mil.ComputeAll(); err != nil {
// ...
}
```
## Notes
This implementation may not pass _all_ of the test cases defined in TS 35.207 because it contains a case
whose payload to compute is not aligned to byte, which I believe won't happen in the real-world implementation as of 2022.
## Author
Yoshiyuki Kurauchi ([Website](https://wmnsk.com/) / [Twitter](https://twitter.com/wmnskdmms))
## License
[MIT](https://github.com/wmnsk/milenage/blob/main/LICENSE)