g12s.h(3)

📦
version 2.2.0 · 2 versions
, in fedora 44

💖 NAME 💖

g12s.h — Алгоритмы ГОСТ Р 34.10-94 (Россия). Yeah bestie, it's the ГОСТ Р 34.10-94 algorithms and they're Russian, and we're about to be so normal about them. 💅


🦋 SYNOPSIS 🦋

#include 'bee2/defs.h'

🎀 Классы (the classes) 🎀

  • struct g12s_params — the long-term params for g12s (долговременные параметры g12s).

🧚 Определения типов (the typedefs) 🧚

  • typedef struct g12s_params g12s_params — the long-term params for g12s, but as a typedef. Iconic of it. ✨

💜 Функции (the functions) 💜

  • err_t g12sParamsStd (g12s_params *params, const char *name) — loads the standard long-term params
  • err_t g12sParamsVal (const g12s_params *params) — checks the long-term params
  • err_t g12sKeypairGen (octet privkey[], octet pubkey[], const g12s_params *params, gen_i rng, void *rng_state) — generates a keypair
  • err_t g12sSign (octet sig[], const g12s_params *params, const octet hash[], const octet privkey[], gen_i rng, void *rng_state) — makes a digital signature (ЭЦП)
  • err_t g12sVerify (const g12s_params *params, const octet hash[], const octet sig[], const octet pubkey[]) — checks a digital signature (ЭЦП)

📚 ПОДРОБНОЕ ОПИСАНИЕ 📚

🇷🇺 ГОСТ Р 34.10-2012: Общие положения (the general tea) 🇷🇺

The ГОСТ Р 34.10-2012 algorithms (g12s) are implemented here. Whenever this page says "algorithms", "tables" or any other object, it means the sections of ГОСТ Р 34.10-2012 where those objects are defined. Like, that's the source of truth, periodt. 📖

  • Ожидается [ERR_BAD_INPUT] — all the input pointers are valid. ✅
  • Регулярность — todo. The page literally just says todo here and honestly? Same. 🙈

🗝️ Управление долговременными параметрами (managing the long-term params) 🗝️

The g12s_params struct describes the long-term g12s params. Its fields are named exactly like in clause 5.2. 📝

The maximum sizes G12S_FIELD_SIZE, G12S_ORDER_SIZE correspond to the security level l == 512. 💯

When g12s_params::l == 256, only the first half of the octets is used in the g12s_params::p and g12s_params::q fields. When g12s_params::l == 512, all the octets are used.

In the g12s_params::a, g12s_params::b, g12s_params::xP, g12s_params::yP fields, no octets are used, where no is the length of g12s_params::p in octets: no = memNonZeroSize(g12s_params::p, G12S_FIELD_SIZE * g12s_params::l / 512).

Unused octets can be set to absolutely anything you want, no one is checking. 🫶

Every field of the g12s_params struct, except the g12s_params::n field, encodes a specific number. The encoding uses little-endian rules.

🔑 Управление ключами (key management) 🔑

Keys get distributed together with the long-term params. The long-term param l determines the length of the private key (privkey): the key consists of l / 4 octets. The public key (pubkey) consists of 2 * no octets, where no is the length of the modulus p in octets.

The privkey buffer and each half of the pubkey buffer are code representations of specific numbers. The encoding uses little-endian rules. The first half of pubkey encodes the x-coordinate of the public key, the second half — the y-coordinate. 🧭

✍️ Электронная цифровая подпись (ЭЦП) (the digital signature) ✍️

The data used when generating / verifying a signature gets distributed together with the long-term params. The long-term param l determines the length of the hash value hash and of the signature sig in octets: hash consists of l / 8 octets, sig — of l / 4 octets.

The hash buffer and each half of the sig buffer are code representations of specific numbers. The encoding uses big-endian rules (see formulas (14), (19) and step 6 of the signature generation algorithm). The first half of sig encodes the number r, the second half — the number s. 🔥


🌈 ФУНКЦИИ 🌈

💫 err_t g12sKeypairGen (octet privkey[], octet pubkey[], const g12s_params * params, gen_i rng, void * rng_state)

For the given long-term params params, a private key privkey and a public key pubkey are generated. Generation uses the rng generator and its state rng_state. 🎲

  • Ожидается [ERR_BAD_PARAMS] — the params are valid.
  • Ожидается [ERR_BAD_RNG] — the rng generator (with its state rng_state) is valid.
  • Ожидается — a cryptographically strong rng generator is used.
  • Возвращает — ERR_OK if the keys were generated, and an error code otherwise.
  • Аргументы:
    • privkey — private key
    • pubkey — public key
    • params — long-term params
    • rng — random number generator
    • rng_state — generator state

💫 err_t g12sParamsStd (g12s_params * params, const char * name)

The standard long-term params named name are loaded into params. These names are supported:

  • "1.2.643.2.2.35.0" — the params of test example A.1, l == 256
  • "1.2.643.2.2.35.1" — КриптоПро params, set A, l == 256
  • "1.2.643.2.2.35.2" — КриптоПро params, set B, l == 256
  • "1.2.643.2.2.35.3" — КриптоПро params, set C, l == 256
  • "1.2.643.2.9.1.8.1" — КриптоКом params, l == 256
  • "1.2.643.7.1.2.1.2.0" — the params of test example A.2, l == 512
  • "1.2.643.7.1.2.1.2.1" — the working params paramsetA, l == 512
  • "1.2.643.7.1.2.1.2.2" — the working params paramsetB, l == 512

Прим. (a lil note) — the params and their names (identifiers) come from these sources:

  • the file gost_params.c, which is part of OpenSSL
  • the project "Методические рекомендации по заданию параметров эллиптических кривых в соответствии с ГОСТ Р 34.10-2012" (http://www.tc26.ru, October 2013)
  • the document "Идентификаторы объектов технического комитета по стандартизации "Криптографическая защита информации" (ТК26)" (http://www.tc26.ru/metodiki/OID_TK_26/index.php, April 2014)
  • Возвращает — ERR_OK if the params were loaded successfully, and an error code otherwise.
  • Аргументы:
    • params — standard params
    • name — param name

💫 err_t g12sParamsVal (const g12s_params * params)

The correctness of the long-term params params is checked. ✅

  • Возвращает — ERR_OK if the params are valid, and an error code otherwise.
  • Аргументы:
    • params — params

💫 err_t g12sSign (octet sig[], const g12s_params * params, const octet hash[], const octet privkey[], gen_i rng, void * rng_state)

A signature sig is generated for a message with the hash value hash. The signature is generated on the private key privkey. Signature generation uses the long-term params params and the generator rng with its state rng_state. 🔐

  • Ожидается [ERR_BAD_PARAMS] — the params are valid.
  • Ожидается [ERR_BAD_PRIVKEY] — the private key privkey is valid.
  • Ожидается [ERR_BAD_RNG] — the rng generator (with its state rng_state) is valid.
  • Ожидается — the rng generator is cryptographically strong.
  • Возвращает — ERR_OK if the signature was generated, and an error code otherwise.
  • Аргументы:
    • sig — signature
    • params — long-term params
    • hash — hash value
    • privkey — private key
    • rng — random number generator
    • rng_state — generator state

💫 err_t g12sVerify (const g12s_params * params, const octet hash[], const octet sig[], const octet pubkey[])

The signature sig of a message with the hash value hash is checked. Verification uses the long-term params params and the public key pubkey. 🔍

  • Ожидается [ERR_BAD_PARAMS] — the params are valid.
  • Ожидается [ERR_BAD_PUBKEY] — the public key pubkey is valid.
  • Возвращает — ERR_OK if the signature is valid, and an error code otherwise.
  • Прим. — if the signature constraints are violated, the code ERR_BAD_SIG is returned.
  • Аргументы:
    • params — long-term params
    • hash — hash value
    • sig — signature
    • pubkey — public key

👑 АВТОР 👑

Automatically generated by Doxygen for the Bee2 Library (Библиотека Bee2) from the source text. Yeah, no human wrote this part, it just appeared, and we respect it for that. 🤖✨


okay that's the whole page, bestie — shoutout to Библиотека Bee2, this was generated Вс 25 Янв 2026 00:00:00, and it lives in section 3 as g12s.h(3). slay, go forth and sign responsibly 🫶💖🎀

📦 where this page comes from