In order to stay compatible with the original BSD interface, one can
check for existence of the CIOCGSESSINFO define, like done here.
---
 examples/cipher.c |   36 ++++++++++++++++++++++++++++++++++++
 examples/hmac.c   |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/examples/cipher.c b/examples/cipher.c
index 4ad1ec9..9f19c5e 100644
--- a/examples/cipher.c
+++ b/examples/cipher.c
@@ -25,6 +25,9 @@ test_crypto(int cfd)
        char key[KEY_SIZE];
 
        struct session_op sess;
+#ifdef CIOCGSESSINFO
+       struct session_info_op siop;
+#endif
        struct crypt_op cryp;
 
        memset(&sess, 0, sizeof(sess));
@@ -42,6 +45,16 @@ test_crypto(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+                       siop.cipher_info.cra_name, 
siop.cipher_info.cra_driver_name);
+#endif
+
        plaintext = (char *)(((unsigned long)plaintext_raw + sess.alignmask) & 
~sess.alignmask);
        ciphertext = (char *)(((unsigned long)ciphertext_raw + sess.alignmask) 
& ~sess.alignmask);
        memset(plaintext, 0x15, DATA_SIZE);
@@ -68,6 +81,16 @@ test_crypto(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+                       siop.cipher_info.cra_name, 
siop.cipher_info.cra_driver_name);
+#endif
+
        /* Decrypt data.encrypted to data.decrypted */
        cryp.ses = sess.ses;
        cryp.len = DATA_SIZE;
@@ -124,6 +147,9 @@ static int test_aes(int cfd)
        char key2[KEY_SIZE];
 
        struct session_op sess;
+#ifdef CIOCGSESSINFO
+       struct session_info_op siop;
+#endif
        struct crypt_op cryp;
 
        memset(&sess, 0, sizeof(sess));
@@ -176,6 +202,16 @@ static int test_aes(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested cipher CRYPTO_AES_CBC, got %s with driver %s\n",
+                       siop.cipher_info.cra_name, 
siop.cipher_info.cra_driver_name);
+#endif
+
        plaintext2 = (char *)(((unsigned long)plaintext2_raw + sess.alignmask) 
& ~sess.alignmask);
        memcpy(plaintext2, plaintext2_data, BLOCK_SIZE);
 
diff --git a/examples/hmac.c b/examples/hmac.c
index 3a308c9..549e946 100644
--- a/examples/hmac.c
+++ b/examples/hmac.c
@@ -29,6 +29,9 @@ test_crypto(int cfd)
                        key[KEY_SIZE];
        } data;
        struct session_op sess;
+#ifdef CIOCGSESSINFO
+       struct session_info_op siop;
+#endif
        struct crypt_op cryp;
        uint8_t mac[AALG_MAX_RESULT_LEN];
        uint8_t oldmac[AALG_MAX_RESULT_LEN];
@@ -52,6 +55,16 @@ test_crypto(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested mac CRYPTO_SHA1, got %s with driver %s\n",
+                       siop.hash_info.cra_name, 
siop.hash_info.cra_driver_name);
+#endif
+
        cryp.ses = sess.ses;
        cryp.len = sizeof("what do ya want for nothing?")-1;
        cryp.src = "what do ya want for nothing?";
@@ -85,6 +98,16 @@ test_crypto(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested mac CRYPTO_MD5_HMAC, got %s with driver %s\n",
+                       siop.hash_info.cra_name, 
siop.hash_info.cra_driver_name);
+#endif
+
        cryp.ses = sess.ses;
        cryp.len = sizeof("what do ya want for nothing?")-1;
        cryp.src = "what do ya want for nothing?";
@@ -118,6 +141,18 @@ test_crypto(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested cipher CRYPTO_AES_CBC and mac CRYPTO_SHA1_HMAC,"
+              " got cipher %s with driver %s and hash %s with driver %s\n",
+                       siop.cipher_info.cra_name, 
siop.cipher_info.cra_driver_name,
+                       siop.hash_info.cra_name, 
siop.hash_info.cra_driver_name);
+#endif
+
        /* Encrypt data.in to data.encrypted */
        cryp.ses = sess.ses;
        cryp.len = sizeof(data.in);
@@ -170,6 +205,9 @@ static int
 test_extras(int cfd)
 {
        struct session_op sess;
+#ifdef CIOCGSESSINFO
+       struct session_info_op siop;
+#endif
        struct crypt_op cryp;
        uint8_t mac[AALG_MAX_RESULT_LEN];
        uint8_t oldmac[AALG_MAX_RESULT_LEN];
@@ -193,6 +231,16 @@ test_extras(int cfd)
                return 1;
        }
 
+#ifdef CIOCGSESSINFO
+       siop.ses = sess.ses;
+       if (ioctl(cfd, CIOCGSESSINFO, &siop)) {
+               perror("ioctl(CIOCGSESSINFO)");
+               return 1;
+       }
+       printf("requested mac CRYPTO_SHA1, got %s with driver %s\n",
+                       siop.hash_info.cra_name, 
siop.hash_info.cra_driver_name);
+#endif
+
        cryp.ses = sess.ses;
        cryp.len = sizeof("what do")-1;
        cryp.src = "what do";
-- 
1.7.3.2



_______________________________________________
Cryptodev-linux-devel mailing list
Cryptodev-linux-devel@gna.org
https://mail.gna.org/listinfo/cryptodev-linux-devel

Reply via email to