<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <span class="im">The call crypto:block_decrypt(blowfish_cbc, ...</span><br>
    <br>
    ends up in C-function bf_cbc_crypt() in <br>
    <br>
    $ERL_TOP/lib/crypto/c_src/crypto.c<br>
    <br>
    which in turn calls OpenSSL functions BF_set_key() and
    BF_cbc_encrypt().<br>
    <br>
    <br>
    If you know the exact plain text to expect, have you tried doing<br>
    the reverse with crypto:block_encrypt.<br>
    <br>
    What about trying the same with an unsensitive key that you can
    share.<br>
    <br>
    Still don't understand what role IvSpec plays in all this.<br>
    <br>
    <br>
    /Sverker, Erlang/OTP<br>
    <br>
    <br>
    On 11/09/2015 02:17 PM, Bogdan Andu wrote:<br>
    <blockquote
cite="mid:CAP7yTnwZiPHif=8jwpzZfn40=6uEYGbKnb_yQ8BCQBqM+-+tdg@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">I have DataToBeDecrypted
        <div><br>
          and one-liner in erlang shell:<span class="im"><br>
            <br>
            crypto:block_decrypt(blowfish_cbc, hexstr2bin(Key), IV,
            Rest).<br>
            <br>
          </span></div>
        <div>where DataToBeDecrypted is formatted as follows:<br>
        </div>
        <div><br>
          <<IvSpec:8/binary, IV:8/binary, Rest/binary>> =
          DataToBeDecrypted<br>
          <br>
        </div>
        <div>I can extract IvSpec = <<"RandomIV">>,<br>
          <br>
        </div>
        <div>Next 8 octets is IV,<br>
          <br>
        </div>
        <div>Rest should bet the actual quantity to be decrypted,<br>
          <br>
        </div>
        <div>and the function call above fails to produce the plain text
          expected,<br>
        </div>
        <div>only garbage<br>
          <br>
        </div>
        Unfortunately Key is sensitive and cannot disclose the value.</div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Mon, Nov 9, 2015 at 11:40 AM, Rad
          Gruchalski <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:radek@gruchalski.com" target="_blank">radek@gruchalski.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div>Bogdan,</div>
            <div><br>
            </div>
            <div> I wonder if you can show us a minimum viable example.
            </div>
            <div>How do you encrypt, how do you decrypt. Can you present
              such code?</div>
            <div>
              <p
                style="font-family:Helvetica;font-size:10pt;margin-bottom:0cm">
              </p>
              <p
                style="font-family:Helvetica;font-size:10pt;margin-bottom:0cm">
              </p>
              <p style="margin-bottom:0cm"> </p>
              <p style="margin-bottom:0cm"><font color="#000000"><font
                    face="Helvetica, sans-serif"><font
                      style="font-size:9pt">Kind
                      regards,
<br>
                      Radek
                      Gruchalski<br>
                      
</font></font></font><font face="Helvetica,
                  sans-serif"><font style="font-size:9pt"><a
                      moz-do-not-send="true"
                      href="mailto:radek@gruchalski.com" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:radek@gruchalski.com">radek@gruchalski.com</a></a><a
                      moz-do-not-send="true"
                      href="mailto:radek@gruchalski.com" target="_blank">
</a></font></font><font
                  color="#0084d1"><font face="Helvetica, sans-serif"><font
                      style="font-size:9pt"><br>
                    </font></font></font><a moz-do-not-send="true"
                  href="http://de.linkedin.com/in/radgruchalski/"
                  target="_blank"><font color="#0084d1"><font
                      face="Helvetica, sans-serif"><font
                        style="font-size:9pt">de.linkedin.com/in/radgruchalski/</font></font></font></a><font
                  color="#000000"><font face="Helvetica, sans-serif"><font
                      style="font-size:9pt"><br>
                      <br>
                    </font></font></font><font color="#878787"><font
                    face="Helvetica, sans-serif"><font
                      style="font-size:8pt"><b>Confidentiality:<br>
                      </b></font></font></font><font color="#878787"><font
                    face="Helvetica, sans-serif"><font
                      style="font-size:8pt">This
                      communication is intended for the above-named
                      person and may be
                      confidential and/or legally privileged.<br>
                      If it has come to you in
                      error you must take no action based on it, nor
                      must you copy or show
                      it to anyone; please delete/destroy and inform the
                      sender
                      immediately.</font></font></font></p>
            </div>
            <div class="HOEnZb">
              <div class="h5">
                <p style="color:#a0a0a8">On Monday, 9 November 2015 at
                  10:38, Bogdan Andu wrote:</p>
                <blockquote type="cite"
style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px">
                  <span>
                    <div>
                      <div>
                        <div dir="ltr">
                          <div>
                            <div>
                              <div>
                                <div>
                                  <div>
                                    <div><br>
                                    </div>
                                    hi,<br>
                                    <br>
                                  </div>
                                  I really need some pointers about this
                                  issue<br>
                                  <br>
                                </div>
                                as i tried all kinds of combinations of
                                IV and body<br>
                              </div>
                              to be decrypted.<br>
                              <br>
                            </div>
                            Am i missing something or there is a bug in
                            cipher<br>
                          </div>
                          blowfish_cbc ?<br>
                          <div><br>
                            <div>
                              <div>
                                <div><br>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                        <div><br>
                          <div>On Thu, Nov 5, 2015 at 3:51 PM, Bogdan
                            Andu <span dir="ltr"><<a
                                moz-do-not-send="true"
                                href="mailto:bog495@gmail.com"
                                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:bog495@gmail.com">bog495@gmail.com</a></a>></span>
                            wrote:<br>
                            <blockquote type="cite">
                              <div>
                                <div dir="ltr">
                                  <div>
                                    <div>
                                      <div> Data to be decrypted
                                        (arrived on socket, etc) is:<br>
                                        <<IvSpec:8/binary,
                                        IV:8/binary, Rest/binary>>
                                        = EncryptedData<br>
                                        <br>
                                      </div>
                                      IV is ectracted form the 8-byte
                                      prepanded value preceding <br>
                                    </div>
                                    IvSpec which has the value RandomIV.<br>
                                    <br>
                                  </div>
                                  decryption of Rest should be
                                  initialized with IV.<br>
                                  <br>
                                </div>
                                <div>
                                  <div>
                                    <div><br>
                                      <div>On Thu, Nov 5, 2015 at 3:38
                                        PM, Radoslaw Gruchalski <span
                                          dir="ltr"><<a
                                            moz-do-not-send="true"
                                            href="mailto:radek@gruchalski.com"
                                            target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:radek@gruchalski.com">radek@gruchalski.com</a></a>></span>
                                        wrote:<br>
                                        <blockquote type="cite">
                                          <div>
                                            <div
                                              style="padding-left:16px;padding-right:16px;padding-bottom:8px">
                                              <div>You say your data is:</div>
                                              <div><br>
                                              </div>
                                              <div><<IvSpec>>
                                                ==
                                                <<RandomIv>></div>
                                              <div><br>
                                              </div>
                                              <div>But you read:</div>
                                              <div><br>
                                              </div>
                                              <div>Is your data
                                                <<IvSpec:8/binary,
                                                IV:8/binary,
                                                Rest/binary>></div>
                                              <div><br>
                                              </div>
                                              <div>Should it not be
                                                just:</div>
                                              <div><br>
                                              </div>
                                              <div><<IV:8/binary,
                                                Rest/binary>></div>
                                              <div><br>
                                              </div>
                                              <div>?<br>
                                                <br>
                                                <div>Sent from <a
                                                    moz-do-not-send="true"
href="http://aka.ms/Ox5hz3" target="_blank">Outlook</a></div>
                                                <br>
                                              </div>
                                            </div>
                                            <div>_____________________________<br>
                                              From: Bogdan Andu <<a
                                                moz-do-not-send="true"
                                                dir="ltr"
                                                href="mailto:bog495@gmail.com"
                                                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:bog495@gmail.com">bog495@gmail.com</a></a>><br>
                                              Sent: Thursday, November
                                              5, 2015 2:26 p.m.<br>
                                              Subject:
                                              [erlang-questions]
                                              blowfish cbc mode decrypt<br>
                                              To: Erlang <<a
                                                moz-do-not-send="true"
                                                dir="ltr"
                                                href="mailto:erlang-questions@erlang.org"
                                                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></a>>
                                              <div>
                                                <div><br>
                                                  <br>
                                                  <br>
                                                  <div dir="ltr">
                                                    <div>
                                                      <div>
                                                        <div>
                                                          <div>
                                                          <div>
                                                          <div>
                                                          <div>
                                                          <div>
                                                          <div> Hi, <br>
                                                          <br>
                                                          </div>
                                                          I have a
                                                          stream of data
                                                          called
                                                          EncryptedData
                                                          (with randomiv
                                                          header
                                                          specification).
                                                          <br>
                                                          I want to
                                                          decrypt 
                                                          using: <br>
                                                          crypto:block_decrypt(blowfish_cbc,
                                                          hexstr2bin(Key),
                                                          IV, Rest). <br>
                                                          <br>
                                                          </div>
                                                          <div> where: <br>
                                                          </div>
                                                          <div> <br>
                                                          EncryptedData
                                                          is formatted
                                                          as follows: <br>
                                                          </div>
                                                          <<IvSpec:8/binary,
                                                          IV:8/binary,
                                                          Rest/binary>>
                                                          <br>
                                                          <br>
                                                          </div>
                                                          IvSpec ==
                                                          <<"RandomIV">>
                                                          <br>
                                                          <br>
                                                          </div>
                                                          However the
                                                          decryption
                                                          does not works
                                                          and garbage is
                                                          generated <br>
                                                          </div>
                                                          <div> (the
                                                          function  ) .
                                                          <br>
                                                          </div>
                                                          <div> <br>
                                                          </div>
                                                          What could be
                                                          done given the
                                                          fact that IV
                                                          is an 8-byte
                                                          quantity <br>
                                                          </div>
                                                          the Key is
                                                          formatted
                                                          according to
                                                          crypto test
                                                          suites and is
                                                          16 bytes long
                                                          <br>
                                                          <br>
                                                        </div>
                                                        Am I missing
                                                        something? <br>
                                                        <br>
                                                      </div>
                                                      Thanks, <br>
                                                      <br>
                                                    </div>
                                                    Bogdan <br>
                                                  </div>
                                                  <br>
                                                  <br>
                                                </div>
                                              </div>
                                            </div>
                                          </div>
                                        </blockquote>
                                      </div>
                                      <br>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </blockquote>
                          </div>
                          <br>
                        </div>
                      </div>
                    </div>
                  </span> </blockquote>
                <div> <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>