# scala.reflect.internal.StdNames and FIPS 140

**URL:** <https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859>\
**Category:** Language Design\
**Created:** [November 21, 2024, 6:26pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859 "2024-11-21T18:26:51Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![LannyRipple](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lannyripple/32/2485_2.png) [@LannyRipple](https://contributors.scala-lang.org/u/LannyRipple)\
**Post date:** [November 21, 2024, 6:26pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/1 "2024-11-21T18:26:51Z")

</div>

(Can’t argue this is a language bug. The scala/bug README suggests this forum as the appropriate place to raise such a feature request).

Issue:  
Scala uses MD5 in scala.reflect.internal.StdNames via the Java MD5 MessageDigest. If using reflection in a Scala compiled program on the JVM in a FIPS 140 compliant environment the MD5 MessageDigest is not an allowed cryptographic algorithm.

Desired solution:  
Use a hashing algorithm internally for Scala that is FIPS 140 compliant (e.g., SHA-256).

Additional:  
I realize MD5 usage here isn’t in a cryptographic context. Java doesn’t seem to care and by default disables MD5 for FIPS 140 compliance.

---

<div class="post-metadata">

**Author:** ![tgodzik](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/tgodzik/32/1759_2.png) [@tgodzik](https://contributors.scala-lang.org/u/tgodzik)\
**Post date:** [November 25, 2024, 9:19am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/2 "2024-11-25T09:19:53Z")

</div>

I guess the best option would be to inline the implementation, though I am not sure how much work that would be. I don’t think we want to switch to SHA256 in this case since it would make things slower.

---

<div class="post-metadata">

**Author:** ![lrytz](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lrytz/32/1653_2.png) [@lrytz](https://contributors.scala-lang.org/u/lrytz)\
**Post date:** [November 25, 2024, 9:48am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/3 "2024-11-25T09:48:15Z")

</div>

I don’t think performance is an issue here. But binary compatibility is, changing it would affect classfile names.

---

<div class="post-metadata">

**Author:** ![sjrd](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sjrd/32/24_2.png) [@sjrd](https://contributors.scala-lang.org/u/sjrd)\
**Post date:** [November 25, 2024, 9:51am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/4 "2024-11-25T09:51:53Z")

</div>

Edit: ah ah, cross post.

Having our own implementation of MD5 is even worse from a security standpoint than using the JDK implementation. At least the one in the JDK was audited. Don’t roll your own crypto!

I’m not concerned about speed in this case. This code path isn’t supposed to be called often. We could even switch to SHA-512.

The problem is that we need to make sure that we’re not breaking binary/TASTy compatibility when we do that. I’m not sure what are the implications here.

---

<div class="post-metadata">

**Author:** ![lrytz](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lrytz/32/1653_2.png) [@lrytz](https://contributors.scala-lang.org/u/lrytz)\
**Post date:** [November 25, 2024, 9:56am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/5 "2024-11-25T09:56:05Z")

</div>

Yeah, something like

```auto
class Abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc {
  class Defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef {
    class Ghighighighighighighighighighighighighighighighighighighighighighighighighi {
      class Jkljkljkljkljkljkljkljkljkljkljkljkljkljkljkl
    }
  }
}

```

Produces the classfile

```auto
Abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc$$$$$c29b78f1186cc3726d75187a2341a7b2$$$$ghighighighi$Jkljkljkljkljkljkljkljkljkljkljkljkljkljkljkl.class

```

It’s a public class and its name cannot change in a minor release.

---

<div class="post-metadata">

**Author:** ![tgodzik](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/tgodzik/32/1759_2.png) [@tgodzik](https://contributors.scala-lang.org/u/tgodzik)\
**Post date:** [November 25, 2024, 10:27am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/6 "2024-11-25T10:27:52Z")

</div>

I mean using our own MD5, which could just be inlined from Java existing one, would not really break a lot. And it wouldn’t be actually used for crypto.

It is a bit controversial, but I don’t see any alternative here.

---

<div class="post-metadata">

**Author:** ![sjrd](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sjrd/32/24_2.png) [@sjrd](https://contributors.scala-lang.org/u/sjrd)\
**Post date:** [November 25, 2024, 1:59pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/7 "2024-11-25T13:59:38Z")

</div>

Well, the alternative is the status quo: not to worsen what we have so that we can tick a box in a too-rigid certification process. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![MateuszKowalewski](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/mateuszkowalewski/32/77_2.png) [@MateuszKowalewski](https://contributors.scala-lang.org/u/MateuszKowalewski)\
**Post date:** [December 9, 2024, 5:26am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/8 "2024-12-09T05:26:45Z")

</div>

I think this is an important issue.

Scala is used especially in finance. There you need to tick all the compliance boxes. Whether it makes sense in context or not, it does not matter. That are hard regulatory requirements, enforced by law.

Copying a MD5 implementation into Scala has no implications for cryptographic security. MD5 is anyway verboten since over a decade for that use-case as MD5 is broken. So doing that should be OK. (Especially as one could make it a private function anyway, just used for the class name hashing purpose.)

But you can’t copy the JDK implementation. Not even if you translated it to Scala. (As that would still form a derived work).

Or is Scala finally going to become GPL software? I would welcome this, but I guess a few others less so…

---

<div class="post-metadata">

**Author:** ![lrytz](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lrytz/32/1653_2.png) [@lrytz](https://contributors.scala-lang.org/u/lrytz)\
**Post date:** [December 9, 2024, 10:24am UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/9 "2024-12-09T10:24:04Z")

</div>

Let’s ask a chatbot to write it, then it’s not our problem where it got it from right? 🧌

But more seriously, we can probably find an implamantation with a compatible license, e.g., [bc-java/core/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java at main · bcgit/bc-java · GitHub](https://github.com/bcgit/bc-java/blob/main/core/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java)

---

<div class="post-metadata">

**Author:** ![tgodzik](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/tgodzik/32/1759_2.png) [@tgodzik](https://contributors.scala-lang.org/u/tgodzik)\
**Post date:** [December 9, 2024, 2:27pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/10 "2024-12-09T14:27:18Z")

</div>

I guess the other solution would be to not use reflection based libraries? We can still compile the programs, just not use scala-reflect jar?

Wouldn’t that be a much smaller issues for Scala 3?

---

<div class="post-metadata">

**Author:** ![LannyRipple](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lannyripple/32/2485_2.png) [@LannyRipple](https://contributors.scala-lang.org/u/LannyRipple)\
**Post date:** [December 17, 2024, 7:55pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/12 "2024-12-17T19:55:03Z")

</div>

So I can say that my employer at least isn’t looking for a minor version fix so binary compatibility shouldn’t be a hinderance. They just want a bug/feature ticket to show they are doing the paperwork. (MD5 gets drawn in on a lot of libraries and programs/utilities. This all started because we use Liquibase for db ddl management. Its tentacles reached out from there to snag several other team’s work and along the way, Scala.)

---

<div class="post-metadata">

**Author:** ![LannyRipple](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lannyripple/32/2485_2.png) [@LannyRipple](https://contributors.scala-lang.org/u/LannyRipple)\
**Post date:** [May 28, 2025, 7:24pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/13 "2025-05-28T19:24:01Z")

</div>

Stirring the pot on this. The process asks that it be discussed here. Done. How can I get a bug created to move to SHA-256 at an appropriate time not to break backward compat?

---

<div class="post-metadata">

**Author:** ![LannyRipple](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lannyripple/32/2485_2.png) [@LannyRipple](https://contributors.scala-lang.org/u/LannyRipple)\
**Post date:** [August 1, 2025, 3:07pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/14 "2025-08-01T15:07:53Z")

</div>

> Stirring the pot on this. The process asks that it be discussed here. Done. How can I get a bug created to move to SHA-256 at an appropriate time not to break backward compat?

What he asked.

---

<div class="post-metadata">

**Author:** ![SethTisue](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sethtisue/32/3185_2.png) [@SethTisue](https://contributors.scala-lang.org/u/SethTisue)\
**Post date:** [August 1, 2025, 4:56pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/15 "2025-08-01T16:56:58Z")

</div>

It seems what’s needed here is a pull request from an interested volunteer, taking Mateusz and Lukas’s suggestion to inline an implementation with a compatible license. From what’s been said here, anyway, it seems such a pull request would likely be accepted.

It seems we _don’t_ have an interested volunteer on the Scala core or compiler teams (though those teams would be on the hook for PR review).

---

<div class="post-metadata">

**Author:** ![SethTisue](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sethtisue/32/3185_2.png) [@SethTisue](https://contributors.scala-lang.org/u/SethTisue)\
**Post date:** [August 1, 2025, 4:58pm UTC](https://contributors.scala-lang.org/t/scala-reflect-internal-stdnames-and-fips-140/6859/16 "2025-08-01T16:58:57Z")

</div>

Oh, if you just need a ticket to exist, feel free to open one at [GitHub - scala/bug: Scala 2 bug reports only. Please, no questions — proper bug reports only.](https://github.com/scala/bug) .

I see now that you refrained from doing it so far out of fear it would be considered an enhancement request and not a bug. We appreciate your caution, but based on the above discussion, consider yourself granted permission to open a ticket on the inlined-MD5 option.

It doesn’t seem there is appetite for switching to SHA256, as that would be quite difficult — unless someone did an analysis proving otherwise, and it seems we don’t have a volunteer to do that analysis.

In any case, any switch to a different algorithm would be out of scope for Scala 2, as far as I can see — it would only have a chance in Scala 3. Scala 2 is in maintenance mode. The inlined-MD5-implementation route seems more appropriate for maintenance mode.
