{"id":24478885,"url":"https://github.com/open-source-firmware/go-tcg-storage","last_synced_at":"2025-04-13T14:20:40.004Z","repository":{"id":39801034,"uuid":"369760877","full_name":"open-source-firmware/go-tcg-storage","owner":"open-source-firmware","description":"Go library for interfacing TCG Storage functions on storage devices","archived":false,"fork":false,"pushed_at":"2023-10-19T14:04:40.000Z","size":3403,"stargazers_count":22,"open_issues_count":25,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T09:09:48.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-source-firmware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-22T08:53:38.000Z","updated_at":"2025-04-03T10:43:43.000Z","dependencies_parsed_at":"2024-06-19T02:08:59.770Z","dependency_job_id":"cfa6da82-20a2-46c4-9353-26c6cc134668","html_url":"https://github.com/open-source-firmware/go-tcg-storage","commit_stats":null,"previous_names":["bluecmd/go-tcg-storage","bluecmd/go-opal"],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-source-firmware%2Fgo-tcg-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-source-firmware%2Fgo-tcg-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-source-firmware%2Fgo-tcg-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-source-firmware%2Fgo-tcg-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-source-firmware","download_url":"https://codeload.github.com/open-source-firmware/go-tcg-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248725091,"owners_count":21151626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T10:13:56.428Z","updated_at":"2025-04-13T14:20:39.982Z","avatar_url":"https://github.com/open-source-firmware.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-tcg-storage\n\n[![Workflow](https://github.com/open-source-firmware/go-tcg-storage/workflows/Release/badge.svg)](https://github.com/open-source-firmware/go-tcg-storage/actions/workflows/release.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/open-source-firmware/go-tcg-storage)](https://goreportcard.com/report/github.com/open-source-firmware/go-tcg-storage)\n[![GoDoc](https://godoc.org/github.com/open-source-firmware/go-tcg-storage?status.svg)](https://pkg.go.dev/github.com/open-source-firmware/go-tcg-storage@main)\n[![Slack](https://slack.osfw.dev/badge.svg)](https://slack.osfw.dev)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/open-source-firmware/go-tcg-storage/blob/master/LICENSE)\n\nGo library for interfacing TCG Storage and Security Subsystem Class (SSC) functions on storage devices.\n\nSupported (or planned) standards:\n\n * [Core](https://trustedcomputinggroup.org/resource/tcg-storage-architecture-core-specification/)\n * [Opal 2.0](https://trustedcomputinggroup.org/resource/storage-work-group-storage-security-subsystem-class-opal/)\n * [Enterprise](https://trustedcomputinggroup.org/resource/storage-work-group-storage-security-subsystem-class-enterprise-specification/)\n * [Ruby](https://trustedcomputinggroup.org/resource/tcg-storage-security-subsystem-class-ruby-specification/)\n\nNeed support for another standard? Let us know by filing a feature request!\n\n## Tools\n\n * [sedlockctl](cmd/sedlockctl/README.md) is a tool that helps you manage SED/TCG drives.\u003cbr\u003e\n   Install it: `go install github.com/open-source-firmware/go-tcg-storage/cmd/sedlockctl@main`\n\n * [tcgsdiag](cmd/tcgsdiag/README.md) lets you list a whole lot of diagnostic information about TCG drives.\u003cbr\u003e\n   Install it: `go install github.com/open-source-firmware/go-tcg-storage/cmd/tcgsdiag@main`\n\n * [tcgdiskstat](cmd/tcgdiskstat/README.md) is like `blkid` or `lsscsi` but for TCG drives.\u003cbr\u003e\n   Install it: `go install github.com/open-source-firmware/go-tcg-storage/cmd/tcgdiskstat@main`\n\n\n## Supported Transports\n\nThe following transports are supported by the library:\n\n * NVMe\n * SATA\n * SAS\n\nNeed another transport? You can do one of two things:\n\n 1. You can implement the `drive` interface yourself to talk to your device.\n 2. You can file a feature request describing your setup and we can discuss implementing it\n\n## Usage\n\nThe library consists of multiple libraries in order to abstract\naway the functionallity the library user does not need to care about.\nThe library does not rely on the in-kernel implementation of\nTCG Opal[[1](https://github.com/torvalds/linux/commit/455a7b238cd6bc68c4a550cbbd37c1e22b64f71c)].\n\nThe most low-level interface is the `drive` interface that implements\nthe `IF-SEND` and `IF-RECV` functions that the TCG Storage standards\nrely on. Likely nobody outside this library will find that library useful.\nUser of the `core` library usually dont neet to care about `drive` for its functionality\nis just to abstract device types from the core library.\n\nOne abstraction up is the `core` library that implements the\nTCG Storage specifications in a quite verbose manner. The guiding\nprinciple with the `core` library is that you should be able to do\nanything with it, but it might require you to know what functions\ncan be called under what circumstances.\nThe `core` supplies the user with the `NewCore` function, which opens a\ngiven device and obtains disk information and Level0Discovery from the device.\n\nFinally you have the `locking` library that implements the most\nlikely reason you are reading this. It allows you to get access\nto, and modify, the locking ranges of a TCG Storage compliant\ndrive without caring much what version of the standards the drive\nis implementing.\n\n### Core Library\n\n```go\nimport (\n\t\"log\"\n\n\ttcg \"github.com/open-source-firmware/go-tcg-storage/pkg/core\"\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/core/table\"\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/core/uid\"\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/drive\"\n)\n\nfunc main() {\n\tcore, err := tcg.NewCore(\"/dev/sda\")\n\tif err != nil {\n\t\tlog.Fatalf(\"tcg.NewCore(/dev/sda) failed: %v\",err)\n\t}\n\tdefer core.Close()\n\n\t// This will work if your drive implements GET_COMID,\n\t// otherwise you will need to figure out the ComID and\n\t// pass it in with WithComID(x)\n\tcs, err := tcg.NewControlSession(d, core.)\n\tif err != nil {\n\t\tlog.Fatalf(\"tcg.NewControlSession(d,d0) failed: %v\", err)\n\t}\n\tdefer cs.Close()\n\ts, err := cs.NewSession(tcg.AdminSP)\n\tif err != nil {\n\t\tlog.Fatalf(\"cs.NewSession(uid.AdminSP) failed: %v\", err)\n\t}\n\tdefer s.Close()\n\n\t// This is how you call a method on your SP:\n\trand, err := table.ThisSP_Random(s, 8 /* bytes to generate */)\n\n\t// You can authenticate using the MSID like this:\n\tmsidPin, err := table.Admin_C_PIN_MSID_GetPIN(s)\n\tif err := table.ThisSP_Authenticate(s, uid.AuthoritySID, msidPin); err != nil {\n\t \tlog.Fatalf(\"Authentication as SID failed!\")\n\t}\n\t// Session is now elevated\n}\n```\n\n### Locking Library\n\nThe most minimal example looks something like this:\n\n```go\n\nimport (\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/drive\"\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/locking\"\n)\n\nfunc main() {\n\td, err := drive.Open(\"/dev/sda\")\n\tdefer d.Close()\n\n\tcs, lmeta, err := locking.Initialize(d)\n\tdefer cs.Close()\n\tl, err := locking.NewSession(cs, lmeta, locking.DefaultAuthorityWithMSID)\n\tdefer l.Close()\n\tfmt.Printf(\"Authenticated user has %d locking ranges\", len(l.Ranges))\n}\n```\n\nA slightly more realistic example looks like this:\n```go\n\nimport (\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/drive\"\n\t\"github.com/open-source-firmware/go-tcg-storage/pkg/locking\"\n)\n\nfunc main() {\n\td, err := drive.Open(\"/dev/sda\")\n\tdefer d.Close()\n\n        password := []byte{} /* Password for Admin1 or BandMaster0 */\n\tcs, lmeta, err := locking.Initialize(d,\n\t\tlocking.WithAuth(locking.DefaultAuthorityWithMSID)\n\t\tlocking.WithTakeOwnership(password),\n\t\tlocking.WithHardening())\n\tdefer cs.Close()\n\tl, err := locking.NewSession(cs, lmeta, locking.DefaultAuthority(password))\n\tdefer l.Close()\n\tfmt.Printf(\"Authenticated user has %d locking ranges\", len(l.Ranges))\n}\n```\n\n## Tested drives\n\nThese drives have been found to work without issues\n\n| Manufacturer | Model | Transport | Features | Notes |\n|--------------|-------|-----------|----------|-------|\n| Corsair | Force MP510 | NVMe | Pyrite v1 | |\n| Intel | P4510 (SSDPE2KX020T8O) | NVMe | Opal v2 | |\n| Intel | P4610 (SSDPE2KE032T8O) | NVMe | Opal v2 | |\n| Sabrent | Rocket 4.0 2TB | NVMe | Pyrite v2 | |\n| Samsung | PM1735 (MZPLJ12THALA-00007) | NVMe | Opal v2 | Shadow MBR missing |\n| Samsung | PM961 (MZVLW512HMJP-000L7) | NVMe | Opal v2 | |\n| Samsung | PM981 (MZVLB512HAJQ-000L7) | NVMe | Opal v2 | |\n| Samsung | PM983 (MZ1LB1T9HALS-00007) | NVMe | Opal v2 | |\n| Samsung | PM9A1 (MZVL2256HCHQ-00B00) | NVMe | Pyrite v2 | |\n| Samsung | PM9A3 (MZQL23T8HCLS-00A07) | NVMe | Opal v2 | |\n| Samsung | SSD 860 | SATA | Opal v2 | |\n| Samsung | SSD 970 EVO Plus | NVMe | Opal v2 | |\n| Samsung | SSD 980 Pro (MZVL2250HCHQ) | NVMe | Opal v2 | |\n| Seagate | 7E2000 (ST2000NX0343) | SAS3 | Enterprise | |\n| Seagate | Exos X14 (ST10000NM0608) | SAS3 | Enterprise | |\n| Seagate | Momentus Thin (ST500LT015) | SATA | Opal v2 | |\n| SK hynix | PC611 (HFS001TD9TNI-L2B0B) | NVMe | Opal v2 | |\n| Toshiba | MG08SCP16TE | SAS3 | Enterprise | |\n\n*Samsung PNs ending in \"7\" seems to indicate Opal v2 features*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-source-firmware%2Fgo-tcg-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-source-firmware%2Fgo-tcg-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-source-firmware%2Fgo-tcg-storage/lists"}