Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GOST-2012 not supported #28

Closed
ubushan opened this issue Mar 1, 2018 · 19 comments
Closed

GOST-2012 not supported #28

ubushan opened this issue Mar 1, 2018 · 19 comments

Comments

@ubushan
Copy link

ubushan commented Mar 1, 2018

  • PyKCS11 version: 1.4.4
  • Python version: 3.5

Hello there!
When I call function C_GetMechanismList (from your example) I can't find there algorithm GOST-2012 in this the list. My token supports algorithm GOST-2012.
This algorithm GOST-2012 is not supported? Will there be support in the near future?
Or am I doing anything wrong?

Thanks!

Mechanism list: ['CKM_RSA_PKCS_KEY_PAIR_GEN', 'CKM_RSA_PKCS', 'CKM_RSA_PKCS_OAEP', 'CKM_MD5', 'CKM_SHA_1', 'CKM_GOSTR3410_KEY_PAIR_GEN', 'CKM_GOSTR3410', 'CKM_GOSTR3410_DERIVE', 'CKR_VENDOR_DEFINED_54321005', 'CKR_VENDOR_DEFINED_54321006', 'CKR_VENDOR_DEFINED_54321007', 'CKM_GOSTR3411', 'CKR_VENDOR_DEFINED_54321012', 'CKR_VENDOR_DEFINED_54321013', 'CKM_GOSTR3410_WITH_GOSTR3411', 'CKR_VENDOR_DEFINED_54321008', 'CKR_VENDOR_DEFINED_54321009', 'CKM_GOST28147_KEY_WRAP', 'CKM_GOST28147_ECB', 'CKM_GOST28147', 'CKM_GOST28147_KEY_GEN', 'CKM_GOST28147_MAC']

@LudovicRousseau
Copy link
Owner

I don't know what you call GOST-2012.
What is the exact PKCS#11 name for that mechanism? It should be something like CKM_GOSTRxyz

Could it be one of the CKR_VENDOR_DEFINED_xxx values?

@ubushan
Copy link
Author

ubushan commented Mar 1, 2018

@LudovicRousseau Thanks for the quick response.

What is the exact PKCS#11 name for that mechanism? It should be something like CKM_GOSTRxyz

Something like that "GOSTR3410-2012"

Could it be one of the CKR_VENDOR_DEFINED_xxx values?

Yeah, I think so too, but which of CKR_VENDOR_DEFINED is "GOSTR3410-2012"?

Thanks.

@LudovicRousseau
Copy link
Owner

If you can find the PKCS#11 specification that defines GOSTR3410-2012 then I will add support for it.

@nekolyanich
Copy link

Hi, new GOST in PKCS11 specification published only in russian. I can post link on it if you need. There are constant defines that your looking at.

#define NSSCK_VENDOR_PKCS11_RU_TEAM 0xD4321000 /* 0x80000000 | 0x54321000 */ 
#define CK_VENDOR_PKCS11_RU_TEAM_TC26           NSSCK_VENDOR_PKCS11_RU_TEAM  
 
/* GOST KEY TYPES */ 
#define CKK_GOSTR3410_256                       CKK_GOSTR3410 
#define CKK_GOSTR3410_512                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x003) 
#define CKK_KUZNECHIK                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x004) 
 
/* GOST OBJECT ATTRIBUTES */ 
#define CKA_GOSTR3410_256PARAMS                 CKA_GOSTR3410PARAMS 
 
/* PKCS #5 PRF Functions */ 
#define CKP_PKCS5_PBKD2_HMAC_GOSTR3411_2012_512 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x003) 
 
/* GOST MECHANISMS */ 
#define CKM_GOSTR3410_256_KEY_PAIR_GEN          CKM_GOSTR3410_KEY_PAIR_GEN  
#define CKM_GOSTR3410_512_KEY_PAIR_GEN          (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x005)  
#define CKM_GOSTR3410_256                       CKM_GOSTR3410  
#define CKM_GOSTR3410_512                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x006)  
#define CKM_GOSTR3410_2012_DERIVE               (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x007)  
#define CKM_GOSTR3410_12_DERIVE                 CKM_GOSTR3410_2012_DERIVE 
#define CKM_GOSTR3410_WITH_GOSTR3411_94         CKM_GOSTR3410_WITH_GOSTR3411 
#define CKM_GOSTR3410_WITH_GOSTR3411_2012_256   (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x008) 
#define CKM_GOSTR3410_WITH_GOSTR3411_2012_512   (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x009) 
#define CKM_GOSTR3410_WITH_GOSTR3411_12_256     CKM_GOSTR3410_WITH_GOSTR3411_2012_256 
#define CKM_GOSTR3410_WITH_GOSTR3411_12_512     CKM_GOSTR3410_WITH_GOSTR3411_2012_512 
#define CKM_GOSTR3410_PUBLIC_KEY_DERIVE         (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x00A) 
 
#define CKM_GOSTR3411_94                        CKM_GOSTR3411 
#define CKM_GOSTR3411_2012_256                  (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x012) 
#define CKM_GOSTR3411_2012_512                  (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x013) 
#define CKM_GOSTR3411_12_256                    CKM_GOSTR3411_2012_256 
#define CKM_GOSTR3411_12_512                    CKM_GOSTR3411_2012_512 
#define CKM_GOSTR3411_94_HMAC                   CKM_GOSTR3411_HMAC 
#define CKM_GOSTR3411_2012_256_HMAC             (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x014) 
#define CKM_GOSTR3411_2012_512_HMAC             (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x015) 
#define CKM_GOSTR3411_12_256_HMAC               CKM_GOSTR3411_2012_256_HMAC 
#define CKM_GOSTR3411_12_512_HMAC               CKM_GOSTR3411_2012_512_HMAC 
#define CKM_TLS_GOST_PRF_2012_256               (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x016) 
#define CKM_TLS_GOST_PRF_2012_512               (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x017) 
#define CKM_TLS_GOST_PRE_MASTER_KEY_GEN         CKM_GOST28147_KEY_GEN 
#define CKM_TLS_GOST_MASTER_KEY_DERIVE_2012_256 (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x018) 
 
#define CKM_KUZNECHIK_KEY_GEN                   (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x019) 
#define CKM_KUZNECHIK_ECB                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01A) 
#define CKM_KUZNECHIK_CTR                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01B) 
#define CKM_KUZNECHIK_CFB                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01C) 
#define CKM_KUZNECHIK_OFB                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01D) 
#define CKM_KUZNECHIK_CBC                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01E) 
#define CKM_KUZNECHIK_MAC                       (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x01F) 
 
#define CKM_MAGMA_ECB                           CKM_GOST28147_ECB 
#define CKM_MAGMA_CTR                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x020) 
#define CKM_MAGMA_CFB                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x021) 
#define CKM_MAGMA_OFB                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x022) 
#define CKM_MAGMA_CBC                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x023) 
#define CKM_MAGMA_MAC                           (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x024) 
 
#define CKM_KDF_4357                            (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x025) 
#define CKM_KDF_GOSTR3411_2012_256              (CK_VENDOR_PKCS11_RU_TEAM_TC26 |0x026) 

@nekolyanich
Copy link

@LudovicRousseau
Copy link
Owner

These tags are in the range of CKM_VENDOR_DEFINED values. I imagine the "real" values in the PKCS#11 standard will be different.

@nekolyanich
Copy link

I use this algos via PyKCS11, and use, for example, CKR_VENDOR_DEFINED_54321012 for GOSTR3411_2012_256 hash.

@eugene-bright
Copy link

eugene-bright commented Jul 2, 2018

Looks like I found technical details.

Specs:

  1. Official documentation in English

Other implementations:

  1. Openssl GOST engine

@LudovicRousseau
Copy link
Owner

Thanks for the links @eugene-bright.
What I need is the PKCS#11 (not GOST) specification with the constants names and values for the GOST algorithms.

@eugene-bright
Copy link

Ok. Does this OASIS spec looks like that you are looking for?
Ctrl+F for 2.45 GOST R 34.10-2001.

@eugene-bright
Copy link

Can't find anything fresh for year 2012 version.
Would dump of exported symbols of proprietary library that implement standard be sufficient?

@LudovicRousseau
Copy link
Owner

@eugene-bright yes, I am looking for something like this
This specification does not define CKK_GOSTR3410_256 or CKM_GOSTR3410_256_KEY_PAIR_GEN or CKM_GOSTR3411_94 as listed by @nekolyanich.

The problem reported by @ubushan is that his PKCS#11 library reports values that are NOT defined in an Oasis standard (that is why PyKCS11 uses CKR_VENDOR_DEFINED_*)

  1. I do not plan to add special CKR_VENDOR_DEFINED_ values in PyKCS11.
  2. the existing PKCS#11 libraries uses CKR_VENDOR_DEFINED_ values

Conclusion: I don't see a solution to that conflict

What I can propose you is to create a PyKCS11_GOST.py file with the constant names and functions you want in order to extend PyKCS11 with GOST support.

@eugene-bright
Copy link

I'm new for this area.
Thanks to this communication with you I've realized that there is major lacking of standards for PKCS11 for GOST family crypto. And now I'm more enlightened.
Thanks for your clarifications.

@LudovicRousseau
Copy link
Owner

@siyavashi Still not a PKCS#11 standard. It does not really help.

@saper
Copy link

saper commented Jan 19, 2021

What I do is I just at the start of my program I add vendor constants to the PyKCS11.CKR/PyKCS11.CKM tables depending on the token I am using.

@LudovicRousseau
Copy link
Owner

If you read Russian https://habr.com/ru/post/549198/

@ubushan ubushan closed this as completed Apr 2, 2022
Repository owner deleted a comment from eugene-bright Apr 3, 2022
@zyv
Copy link

zyv commented Jan 8, 2023

The latest working link to the TC26 document is as follows:

https://www.tc26.ru/standarts/perevody/guidelines-the-pkcs-11-extensions-for-implementing-the-gost-r-34-10-2012-and-gost-r-34-11-2012-russian-standards-.html?sphrase_id=49137

Unfortunately, it seems that it still didn't make it into the OASIS standard.

@eugene-bright
Copy link

It's completely irrelevant now
https://youtu.be/rS3QSDXh9Ic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants