K097 / Encoding and decoding
Protocol Buffers
Google's binary format and mechanism for language- and platform-neutral serialization of structured data.
CRYPTOGRAPHY LAB / K097
Cryptography Lab · Protocol Buffers
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
Protobuf (field 1, uint32)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- Google's binary format and mechanism for language- and platform-neutral serialization of structured data. Source document ↗
- Classification and reversibility
- Binary encoding format supporting serialization and deserialization. Source document ↗
- Key or secret requirements
- Not confirmed in the survey
- Operating principle and structure
- Encodes messages as field keys (field number plus wire type) and values using wire-type rules and varints. Source document ↗
- Key size, block size and parameters
- Field numbers 1–15 use one byte and 16–2047 two bytes; smaller numbers save space. Source document ↗
- Security strength and recommendation
- Use defensive size/recursion limits and filtering before parsing untrusted input. Source document ↗
- Known attacks and vulnerabilities
- Negative varints and deep recursion when parsing untrusted inputs can cause DoS. Source document ↗
- Standards and certification
- The source cites a related IETF RFC 9996 (Informational). Source document ↗
- Typical uses
- Read/write structured data across languages and streams. Source document ↗
- Implementations, libraries and tools
- Language implementations include protobuf-c and protoc-based code generators. Source document ↗
- Decryption or decoding
- Decode binary into objects using generated code/library methods. Source document ↗
- Advantages
- Smaller and faster than JSON, with native bindings generated per language. Source document ↗
- Limitations and cautions
- Treat .proto as trusted code; impose defensive limits for untrusted data. Source document ↗
- Distinguishing encryption, encoding and hashing
- A wire-format key is a uint32 varint containing the field number and wire type, not a cryptographic secret. Source document ↗
Practical examples
Example
Given an object and .proto schema, the runtime encodes fields and values as binary. The receiver deserializes using the same schema. Test1 with a=150 produces bytes such as 08 96 01. No actual secret is used.
Procedure
Define messages and field numbers in .proto, generate code/load schema, set object values and serialize. Decode using the same schema and parse/decode methods. This is serialization, not encryption/decryption; add a separate confidentiality layer.
Scenario
Serialize inter-service RPC requests/responses or mobile event batches into compact binary; receivers decode with the same schema. If storage confidentiality is required, encrypt after serialization.
Pitfalls and alternatives
Schema mismatch and field renumbering cause compatibility or interpretation problems. Limit size/recursion, filter untrusted inputs and patch libraries. Treat .proto like code; separately encrypt/authenticate sensitive data.
References
- Overview | Protocol Buffers Documentation ↗
- mafintosh/protocol-buffers ↗
- Deep dive into the binary algorithm of Protocol Buffers - DEV Community ↗
- Language Guide (proto 3) | Protocol Buffers Documentation ↗
- Overview · protocolbuffers/protobuf · GitHub ↗
- NVD-CVE-2026-6409 ↗
- draft-ietf-dispatch-mime-protobuf-04 - Media Type Registration for Protocol Buffers ↗
- Protocol Buffers implementation in C ↗