Fix strange formatting by indent
[openssl.git] / crypto / evp / e_des3.c
index 6fe6453be152124d74fd0baa1913a87aef21c06d..4275373fd2c54ffcb334da3c41613c38dfd6db88 100644 (file)
 #include <openssl/des.h>
 #include <openssl/rand.h>
 
+/* Block use of implementations in FIPS mode */
+#undef EVP_CIPH_FLAG_FIPS
+#define EVP_CIPH_FLAG_FIPS     0
+
 typedef struct
        {
        union { double align; DES_key_schedule ks[3]; } ks;
@@ -119,7 +123,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                              const unsigned char *in, size_t inl)
 {
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK,
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -144,12 +148,11 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 #ifdef KSSL_DEBUG
        {
         int i;
-        char *cp;
-       printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", ctx, ctx->buf_len);
-       printf("\t iv= ");
+       fprintf(stderr,"des_ede_cbc_cipher(ctx=%p, buflen=%d)\n", ctx, ctx->buf_len);
+       fprintf(stderr,"\t iv= ");
         for(i=0;i<8;i++)
-                printf("%02X",ctx->iv[i]);
-       printf("\n");
+                fprintf(stderr,"%02X",ctx->iv[i]);
+       fprintf(stderr,"\n");
        }
 #endif    /* KSSL_DEBUG */
        if (dat->stream.cbc)
@@ -158,7 +161,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                return 1;
                }
 
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK,
                             &dat->ks1, &dat->ks2, &dat->ks3,
@@ -177,7 +180,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                              const unsigned char *in, size_t inl)
 {
-       if (inl>=EVP_MAXCHUNK)
+       while (inl>=EVP_MAXCHUNK)
                {
                DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, 
                               &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
@@ -207,8 +210,8 @@ static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
        DES_ede3_cfb_encrypt(c,d,1,1,
                             &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
                             (DES_cblock *)ctx->iv,ctx->encrypt);
-       out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8))) |
-                ((d[0]&0x80) >> (unsigned int)(n%8));
+       out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8)))
+               | ((d[0]&0x80) >> (unsigned int)(n%8));
        }
 
     return 1;
@@ -303,11 +306,14 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
 #ifdef KSSL_DEBUG
        {
         int i;
-        printf("des_ede3_init_key(ctx=%lx)\n", ctx);
-       printf("\tKEY= ");
-        for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
-       printf("\t IV= ");
-        for(i=0;i<8;i++) printf("%02X",iv[i]); printf("\n");
+        fprintf(stderr,"des_ede3_init_key(ctx=%p)\n", ctx);
+       fprintf(stderr,"\tKEY= ");
+        for(i=0;i<24;i++) fprintf(stderr,"%02X",key[i]); fprintf(stderr,"\n");
+       if (iv) 
+               {
+               fprintf(stderr,"\t IV= ");
+               for(i=0;i<8;i++) fprintf(stderr,"%02X",iv[i]); fprintf(stderr,"\n");
+               }
        }
 #endif /* KSSL_DEBUG */
 
@@ -466,7 +472,8 @@ static int des_ede3_wrap_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
 static const EVP_CIPHER des3_wrap = {
        NID_id_smime_alg_CMS3DESwrap,
        8, 24, 0,
-       EVP_CIPH_WRAP_MODE|EVP_CIPH_CUSTOM_IV|EVP_CIPH_FLAG_CUSTOM_CIPHER,
+       EVP_CIPH_WRAP_MODE|EVP_CIPH_CUSTOM_IV|EVP_CIPH_FLAG_CUSTOM_CIPHER
+               |EVP_CIPH_FLAG_DEFAULT_ASN1,
        des_ede3_init_key, des_ede3_wrap_cipher,
        NULL,   
        sizeof(DES_EDE_KEY),